# Floyd's cycle and choosing smart indexing

So I'm trying to implement something using Floyd's cycle. However, while there must be a solution, the while loop doesn't think so and I'm wondering why. This is my code:

```
p=1013;
g=3;
h=245;
G=[g];
a=[1];
b=[0];
a_found=0;
def t_next(i,t):
if t%3==0:
G.append((G[i]*g)%p);
elif t%3==1:
G.append((G[i]*h)%p);
else:
G.append((G[i]^2)%p);
def a_next(i,t):
if t%3==0:
a.append((a[i]+1)%p);
elif t%3==1:
a.append((a[i])%p);
else:
a.append((2*a[i])%p);
def b_next(i,t):
if t%3==0:
b.append((b[i])%p);
elif t%3==1:
b.append((b[i]+1)%p);
else:
b.append((2*b[i])%p);
i=1;
c=1;
while a_found != 1:
n=i;
for k in range(n,2*n+1):
j=k-1;
t_next(j,G[j]);
a_next(j,G[j]);
a
b_next(j,G[j]);
i+=1;
if G[c]==G[2*c]:
a_found=1;
print [i,G[c],G[2*c],a[c],a[2*c],b[c],b[2*c]]
else:
c+=1;
```

The code contains three functions that compute new values of some values a, b and G which I store in a big list and compare two elements G[i] and G[2*i] in each round. Somehow, it never stops. And also I notice that I compute a lot of values multiple times and I don't know how to implement that better. I want to compute each time the values at indices 2 to 4, 3 to 6, 4 to 8, 5 to 10 and compare G[i] and G[2i]. But I guess I messed up the list G. Any suggestions are very welcome!