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 |