# Revision history [back]

Use the .isqrt() method to get the floor of the square root of an integer, as an integer.

That seems to work well for the examples suggested in the question.

Define juggle and print_juggle_sequence as follows:

def juggle(n):
if n % 2:
return (n^3).isqrt()
return n.isqrt()

def print_juggle_sequence(x):
print x
while x > 1:
x = juggle(x)
print x


Then try it on 37:

sage: print_juggle_sequence(37)
37
225
3375
196069
86818724
9317
899319
852846071
24906114455136
4990602
2233
105519
34276462
5854
76
8
2
1


or on 48443:

sage: print_juggle_sequence(48443)
48443
10662193
34815273349
6496130099313865
523578821252958052233532
723587466207
615512041010804067
482897358660562651148793788
21974925680433
103012783516625098121
1045530445028727953685811220915
...
18392638965492294541243350929469903670518362838411978378223645946128324146
4288664007064705289494967442314405131
8881432808181494071360574181865431001179156074769485216
2980173284925139058877740732
54590963399862
7388569
20083550847
2846169433517467
151841723749529535094491
59167972552621245915902054390059896
243244676308899401
119967888751182910434786797
1314006531652570971499311449697128320012
36249228014573923771
218246929826088259128572354715
101958212868994286046069755788632123549931710
10097435955181606698838
100485998801
31853585940530752
178475729
2384343086560
1544131
1918784550
43803
9167602
3027
166540
408
20
4
2
1