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

2 | No.2 Revision |

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

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.