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
/into//it works just fine. Suppressed unneeded output version you can try online – Alexey Burdin Jun 08 '20 at 12:45divwould be true,not divwould be false and the interpreter will have to check the second expression inassert not div or sum(rem_array)%(n-1)==0-- and raiseAssertionErrorif it isFalse, you can try it, there will be in 'debug' window of tio.run if you convert all the//back into/andrem_array.append(rem)back torem_array.append(round(rem)). What was the programming language you learned before python? Pascal, I guess? Not many languages useroundso wide as Pascal does. Thanks. – Alexey Burdin Jun 08 '20 at 12:54