All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
2^89 and 2^98 (Posted on 2024-01-09) Difficulty: 3 of 5
Find the smallest 89-digit integer which is a multiple of 289, and the smallest 98-digit integer which is a multiple of 298, both consisting solely of the digits 8 and 9.

See The Solution Submitted by K Sengupta    
Rating: 4.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer solution | Comment 1 of 2
The decimal number(s) we want is a string of 89 (or 98) 8s with some of the 8s changed to 9s; the key point is that its binary equivalent will end in at least 89 zeros.
Plan for algorithm:  keep slightly adjusting the decimal number to make a progressively longer terminal string of zeros in the binary representation.

Important finding:  the binary representation of 10^n ends with n zeros (since it is 2^n * 5^n). In fact binary for 10^n is 101 followed by n zeros.

Procedure: start with a long string of 8s
How long is the string of terminal 0s in the binary?
Let's say the binary ends with a string of k consecutive zeros.
Now change an 8 to a 9 at location k+1 (counting from the right end)
This adds 10^k to the decimal and is guaranteed to lengthen the consecutive zeros at the end of the binary.
Repeat until the terminal string of zeros in the binary is 89 or more (or 98 or more).

Example:  initially you have ...88888  which is binary ...000111000
Add decimal 1000 to ...88888 to get 89888 which adds         101000 in binary
The new binary for ...89888 becomes ...001100000

  decimal      binary
...88888  ...000111000
...89888  ...001100000

Part One:  89 digits
Binary is:
110010010001001110010010000111000111001001000010000101111100
011000000100101110110001001111100011101001110011001111101101
100011111101001101110011000000011110000111001111010011000001
011010111101010101110010100000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000    
           which ends in 91 zeros
Decimal is:
999999899988998898899888989999888888989898898998899889899998
88898888999898998898989989888  
    which when divided by  2^89 at full precision calculator yields 
161558697231614555082401092391961704994738678758575489807199124

Part Two:  98 digits
Binary is:
101110110100001111010110100001110011011001101000011011100100
101100101001111000110011011000011011000011101010111000110100
101110010001100011011101111001110110111000011011000110110110
100001011101100000100000101001110001011000010101000000000000
000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000
          which ends in 98 zeros
Decimal is:
999988988999999899988998898899888989999888888989898898998899
88989999888898888999898998898989989888  
    which when divided by  2^98 at full precision calculator yields 
    315540887629433735182388126426444767830548314571752815633922913670677

By the way, the decimal answer to part two is simply:
999988988 concatenated with the answer for part one.

Actual output of program
Part One (89)
999999899988998898899888989999888888989898898998899889899998
88898888999898998898989989888
110010010001001110010010000111000111001001000010000101111100
011000000100101110110001001111100011101001110011001111101101
100011111101001101110011000000011110000111001111010011000001
011010111101010101110010100000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
91
0

Part Two (98)
999988988999999899988998898899888989999888888989898898998899
88989999888898888999898998898989989888
101110110100001111010110100001110011011001101000011011100100
101100101001111000110011011000011011000011101010111000110100
101110010001100011011101111001110110111000011011000110110110
100001011101100000100000101001110001011000010101000000000000
000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000
98
0

==========

decimalLength = 89 # or make this 98
stringN = '8' * decimalLength
endzeros = 0

while endzeros < decimalLength:
    binary = base2base(stringN,10,2)
    binLength = len(binary)

    for bin_pos in range(binLength - 1,0,-1):
        if binary[bin_pos] == '1':
            endzeros = binLength - bin_pos - 1
            if endzeros >= decimalLength:
                break
            dec_pos = decimalLength - endzeros - 1
            stringN = stringN[:dec_pos] + '9' + stringN[dec_pos+1:]
            break
    if endzeros >= decimalLength:
        break
print(stringN)
print(base2base(stringN,10,2))
print(endzeros)
print(int(stringN) % (2**decimalLength))

  Posted by Larry on 2024-01-09 13:08:29
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (22)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information