Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int y;
- int cyc=14;
- int p=13;
- int f[p+1]={0};
- bool i[p+1]={0};
- int I[p]={-1};
- for (int j=1; j<p;j++)
- {
- for (int k=1; k<p; k++)
- {
- if((k*j)%p==1)
- {
- I[j]=k;
- }
- }
- }
- for (cyc=1; cyc<p+2; p++)
- {
- int yes=0;
- for (int a=0; a<p; a++)
- {
- for (int b=0; b<p; b++)
- {
- for (int c=0; c<p; c++)
- {
- for (int d=1; d<p; d++)
- {
- if(a*d-b*c!=0)
- {
- //cout << "a="<< a << " b=" << b << " c=" << c << " d=" << d << " \n";
- for (int x=0; x<p; x++)
- {
- if (((c*x+d)%p)!=0)
- {
- f[x]=((a*x+b)*I[(c*x+d)%p])%p;
- //cout << f[x] << " ";
- }
- if (((c*x+d)%p)==0)
- {
- f[x]=p;
- //cout << f[x] << " ";
- }
- i[x]=0;
- }
- if (c==0)
- {
- f[p]=p;
- }
- else
- {
- f[p]=(a*I[c])%p;
- }
- //cout << f[p] << " ";
- i[p]=0;
- for (int x=0; x<p+1; x++)
- {
- if (i[x]==0)
- {
- //cout << "(";
- //cout << x;
- i[x]=1;
- y=f[x];
- int n=1;
- for (int j=x; (j<p+1)&&(i[y]==0); j++)
- {
- //cout << " " << y;
- i[y]=1;
- y=f[y];
- n++;
- }
- if (n==cyc)
- {
- //cout << "cycle found";
- yes=1;
- }
- //cout << n;
- //cout << ") ";
- }
- }
- //cout << "\n";
- }
- }
- }
- }
- }
- cout << cyc << " "<< yes << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement