• + 2 comments

    tortise and hare doesn't make any sense... When the data is not stored up in any structure, the time is enough for just purely comparison and increment count accordingly.

        int a = s%mod;
        int compare = s%mod;
        int count = 1;
        for (int i = 1; i < n; i++)
        {
            a = ((a%mod)*(p%mod)+q%mod)%mod;
            if (a != compare)
            {
                count++;
                compare = a;
            }
            else continue;
        }
        cout<<count;