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

Home > Just Math
2 and 3 power sum (Posted on 2024-07-22) Difficulty: 3 of 5
What is the sum of all the exact divisors of the number N=1988-1 that are of the form 2a*3b, where a and b are greater than zero?

No Solution Yet Submitted by Danish Ahmed Khan    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer solution | Comment 2 of 3 |
You could do a prime factorization of N but all we need is how many factors of 2 and how many factors of 3 there are.  Python can calculate N precisely, but dividing by 2 or 3 is subject to rounding / truncation error.  But with the help of a few small routines to handle the division, we find that 
2^5 is a factor
3^2 is a factor

So in 2^a*3^b, a can be any from 1 to 5; be can be from 1 to 2.

Divisors:  [6, 18, 12, 36, 24, 72, 48, 144, 96, 288]
Sum of these Divisors:  744

-----------
def divBy2(n):
    m = 5*n
    s = str(m)
    if s[-1] == '0':
        return [True,  int(s[:-1])]
    else:
        return [False,n]

def sod(n):
    """ Input an integer.  Returns the Sum of the Digits  """
    aList = list(str(n))
    ans = 0
    for c in aList:
        ans = ans + int(c)
    return ans

def isdivisibleBy3(n):
    if sod(n)%3 == 0:
        return True
    else:
        return False

def divideBy3(n):
    if not isdivisibleBy3(n):
        return 
    s = str(n)
    quotient = ''
    carry = '0'
    for i,v in enumerate(s):
        dividend = int(carry + s[i])
        carry = str(dividend%3)
        if i==0 and dividend // 3 == 0:
            continue
        quotient += str(dividend // 3)
    return [True, int(quotient)]

N = 19**88 - 1

a=0
b=0
newN = N
while divBy2(newN)[0]:
    a += 1
    newN = divBy2(newN)[1]

while isdivisibleBy3(newN):
    b += 1
    newN = divideBy3(newN)[1]

thesum = 0
thefactors = []
for p2 in range(1, a+1):
    for p3 in range(1, b+1):
        factor = 2**p2  *  3**p3
        thefactors.append(factor)
        thesum += factor

print(thefactors)
print(thesum)

  Posted by Larry on 2024-07-22 08:33:09
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 (3)
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