fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(NULL);
  8.  
  9. long long n; cin >> n;
  10. long long a[n][n];
  11. for (int i = 0; i < n; i++)
  12. {
  13. for (int j = 0; j < n; j++)
  14. {
  15. cin >> a[i][j];
  16. }
  17. }
  18. long long tmp = a[0][0];
  19. long long c = 0;
  20. for (int i = 0; i < n; i++)
  21. {
  22. for (int j = 0; j < n; j++)
  23. {
  24. if (tmp == a[i][j]) c++;
  25. }
  26. }
  27. if (c == n*n)
  28. {
  29. cout << 1;
  30. return 0;
  31. }
  32.  
  33. long long x1 = 1, y1 = 0;
  34. c = 0;
  35.  
  36. while (true) {
  37. long long nx1 = (2 * x1 + y1) % n; //day la x
  38. long long ny1 = (x1 + y1) % n; //day la y
  39.  
  40.  
  41. x1 = nx1; y1 = ny1;
  42.  
  43. c++;
  44.  
  45. if (x1 == 1 && y1 == 0) {
  46. break;
  47. }
  48. }
  49. cout << c;
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
 1 1 1
 1 1 1
 1 1 1
stdout
1