I'm very beginner at python. Given code gives error with output. Want to correct it.
The mathematics behind the code is :
Let denote $S_m(n)=1^m+2^m+...+n^m$ and denote $D_x(y)$ is sum of digits of $y$ in base $x$.
Example $S_2(3)=14$ and $14=(1,1,1,0)_2$ then $D_2(14)=3$
Theorem if $x-1\mid y$ then $x-1\mid D_x(y)$
In code, for $n$, output shows "divisible" if $n-1\mid S_m(n-1)$ and shows "oooooooooook" if $n-1\mid D_n(S_m(n-1))$
Problem codes output must show "oooooooooook" if "divisible" had shown but greater value $m$ with greater $n$ does not shows expected result. How to correct it?
n= 2
m = 15
while n < 100:
print("\n n=",n)
num=n
sum_num = 0
for i in range(1, num):
sum_num += i**(m)
n2 = (sum_num)
if(n2%(num-1)== 0):
print("diviasible")
#else:
#print("not divisible")
rem_array = []
while n2 != 0:
mod = n2%n
if mod != 0:
rem = mod
n2 = n2 - rem
rem_array.append(round(rem))
n2 = n2/n
else:
n2 = n2/n
rem_array.append(0)
#print(rem_array[::-1],sum(rem_array))
if(sum(rem_array)%(n-1)==0):
print("oooooooooook")
#else:
#print("not ok")
n += 1
Thank you
Don't see all the points that are not ok, but using
//integer division instead of/float division somewhat helps (tested, that worked).Let me re-write the entire program: