yordanganev

pc20_zadB

Apr 6th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4.  
  5. //#include <limits>
  6. //#include <algorithm>
  7. //#include <math.h>
  8. //#include <bitset> // bitset< 32 >( num ).to_string();
  9. #define ll long long
  10.  
  11. #define print(var) cout << #var << ": " << var << endl;
  12. #define println(var); cout << var << endl;
  13.  
  14. using namespace std;
  15.  
  16.  
  17. int main() {
  18.     ios_base::sync_with_stdio(false);
  19.  
  20.     int a;
  21.     while (cin >> a && a != 0) {
  22.         int* m = new int[a];
  23.         //print(a);
  24.        
  25.         bool sameNum = true;
  26.  
  27.         for (int i = 0; i < a; i++) {
  28.             cin >> m[i];
  29.             if (i > 0) {
  30.                 if (m[i] != m[i - 1]) {
  31.                     sameNum = false;
  32.                 }
  33.             }
  34.         }
  35.         //print(sameNum);
  36.         if (sameNum) {
  37.             cout << sameNum << endl;
  38.         }
  39.         else {
  40.             int n = 2;
  41.  
  42.             //print(n);
  43.  
  44.             sameNum = true;
  45.             int lastPass = 0;
  46.  
  47.             while (n <= a / 2) {
  48.                 int lastN;
  49.                 //print(n);
  50.                 for (int j = 0; j < n; j++) {
  51.                     for (int i = j; i < a; i += n) {
  52.                         if (i > j) {
  53.                             if (lastN != m[i]) {
  54.                                 //print(m[i]);
  55.                                 i = a;
  56.                                 j = a;
  57.                             }
  58.                         }
  59.                         lastN = m[i];
  60.                     }
  61.  
  62.                     if (j == n - 1) {
  63.                         if (lastPass == 0) {
  64.                             lastPass = j + 1;
  65.                             n = a;
  66.                         }
  67.                     }
  68.                 }
  69.  
  70.                 n++;
  71.             }
  72.  
  73.             cout << lastPass << endl;
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment