HP 49G: Minimum Multiplier M of Integer N such that M*N Consists Only of 1's & 0's
|
01-25-2020, 02:12 PM
(This post was last modified: 01-26-2020 11:10 PM by Albert Chan.)
Post: #6
|
|||
|
|||
RE: HP 49G: Minimum Multiplier M of Integer N such that M*N Consists Only of 1's &...
(01-25-2020 05:39 AM)Gerald H Wrote:(01-24-2020 11:48 PM)Albert Chan Wrote: All positive integer N that can be interpreted as valid binary gives minimal P/N = 1 Oh, I see. "minimal P/N" meant min(P)/N, not min(P/N) Sorry, I don't know HP-49G. Algorithm (not optimized) is like this: Code: f = lambda n: n if n<2 else 10*f(n>>1) + (n&1) >>> p(85) 111010 >>> 111010 / 85 1306.0 Note: options to p(n) allowed some optimizations. p(n that can be intepreted as valid binary) = n Remove n trailing 0's: p(10k) = 10 * p(k) ; must be removed first Remove n trailing 5's: p(10k + 5) = 10 * p(2k+1) Remove even n's : p(2k) = 10 * p(k) What is left is n mod 10 = 1,3,7,9 → p(n) must be odd → step = 2 is ok >>> 10 * p(17, step=2) # = p(85) 111010 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)