Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int y;
  8. int cyc=14;
  9. int p=13;
  10. int f[p+1]={0};
  11. bool i[p+1]={0};
  12. int I[p]={-1};
  13. for (int j=1; j<p;j++)
  14. {
  15. for (int k=1; k<p; k++)
  16. {
  17. if((k*j)%p==1)
  18. {
  19. I[j]=k;
  20. }
  21. }
  22. }
  23. for (cyc=1; cyc<p+2; p++)
  24. {
  25. int yes=0;
  26. for (int a=0; a<p; a++)
  27. {
  28. for (int b=0; b<p; b++)
  29. {
  30. for (int c=0; c<p; c++)
  31. {
  32. for (int d=1; d<p; d++)
  33. {
  34. if(a*d-b*c!=0)
  35. {
  36. //cout << "a="<< a << " b=" << b << " c=" << c << " d=" << d << " \n";
  37. for (int x=0; x<p; x++)
  38. {
  39. if (((c*x+d)%p)!=0)
  40. {
  41. f[x]=((a*x+b)*I[(c*x+d)%p])%p;
  42. //cout << f[x] << " ";
  43. }
  44.  
  45. if (((c*x+d)%p)==0)
  46. {
  47. f[x]=p;
  48. //cout << f[x] << " ";
  49. }
  50. i[x]=0;
  51. }
  52. if (c==0)
  53. {
  54. f[p]=p;
  55. }
  56. else
  57. {
  58. f[p]=(a*I[c])%p;
  59. }
  60. //cout << f[p] << " ";
  61. i[p]=0;
  62. for (int x=0; x<p+1; x++)
  63. {
  64. if (i[x]==0)
  65. {
  66. //cout << "(";
  67. //cout << x;
  68. i[x]=1;
  69. y=f[x];
  70. int n=1;
  71. for (int j=x; (j<p+1)&&(i[y]==0); j++)
  72. {
  73. //cout << " " << y;
  74. i[y]=1;
  75. y=f[y];
  76. n++;
  77. }
  78. if (n==cyc)
  79. {
  80. //cout << "cycle found";
  81. yes=1;
  82. }
  83. //cout << n;
  84.  
  85. //cout << ") ";
  86.  
  87. }
  88. }
  89. //cout << "\n";
  90. }
  91. }
  92. }
  93. }
  94. }
  95.  
  96. cout << cyc << " "<< yes << "\n";
  97. }
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement