Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Maybe you get confused by the fact that gcd(0,3) equals 3. If I print each step, it works as expected.

sage: for n in range(9):
... print "n=",n
... if gcd(n,3)==3:
... print "?"
... n=n/3;
... n=n+1;
... print "*",n

n= 0
?
* 1
n= 1
* 1
n= 2
* 2
n= 3
?
* 2
n= 4
* 4
n= 5
* 5
n= 6
?
* 3
n= 7
* 7
n= 8
* 8

Maybe you get confused by the fact that gcd(0,3) equals 3. If I print each step, it works as expected.

sage:

for n in range(9):
...
range(9): print "n=",n
...
"n=",n if gcd(n,3)==3:
...
gcd(n,3)==3: print "?"
...
"?" n=n/3;
...
n=n/3 n=n+1;
...
n=n+1 print "*",n

"*",n n= 0
0 ? * 1 n= 1 * 1 n= 2 * 2 n= 3 ? * 2 n= 4 * 4 n= 5 * 5 n= 6 ? * 3 n= 7 * 7 n= 8 * 8
?
* 1
n= 1
* 1
n= 2
* 2
n= 3
?
* 2
n= 4
* 4
n= 5
* 5
n= 6
?
* 3
n= 7
* 7
n= 8
* 8