HP 49G: Minimum Multiplier M of Integer N such that M*N Consists Only of 1's & 0's
|
01-27-2020, 04:11 PM
(This post was last modified: 01-29-2020 12:29 PM by Albert Chan.)
Post: #9
|
|||
|
|||
RE: HP 49G: Minimum Multiplier M of Integer N such that M*N Consists Only of 1's &...
(01-25-2020 11:50 PM)Albert Chan Wrote: Here is what each "bit" contribute to the mod value, for P(999): We have the same "bit" contribution pattern for N = 333, 111 p(111) = (101*3-1)/9 = 111 p(333) = (103*3-1)/9 = 111111111 p(999) = (109*3-1)/9 = 111111111111111111111111111 We can pull this pattern out as special case, and reduce the combinatorial search. I got an OK from Gerald for posting this fast p(n) Python code. For my old Pentium 3, time for p(n = 0 to 9999) in 21 seconds (4 seconds for my laptop) Code: hd = [ 0, 1, 10, 11, 100, 101, 110, 111, oddp(n) search in chunks for 3 'hex digits' (12 decimal digits) at a time. Since returned p is odd, we only need to check 16×16×8 = 2048 cases / 3 'hex digits' Code: def oddp(n, t=0, td=0, mod=0): # assumed n%10 = 1,3,7,9 >>> p(12345) # = oddp(12345 // 5) * 10 11000111010L >>> p(123456) # = oddp(123456 >> 6) * 10**6 1110110100111000000L |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)