Salvens

Untitled

Jan 13th, 2024
1,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  8.  
  9. //#include <ext/pb_ds/assoc_container.hpp>
  10. //using namespace __gnu_pbds;
  11. //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  12. std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
  13.  
  14. const int INF = 1e18 + 7;
  15. const double EPS = 1e-10;
  16. const int MOD = 1e9 + 7;
  17. const int MAXN = 3e6 + 100;
  18.  
  19. int n;
  20. vector<int> a;
  21.  
  22. int get(int k) {
  23.     int g = -1;
  24.     for (int i = 0; i < k; ++i) {
  25.         int cur = -1;
  26.         for (int j = i; j + k < n; j += k) {
  27.             if (cur == -1) {
  28.                 cur = abs(a[j] - a[j + k]);
  29.             } else {
  30.                 cur = __gcd(cur, abs(a[j] - a[j + k]));
  31.             }
  32.         }
  33.         if (g == -1) {
  34.             g = cur;
  35.         } else {
  36.             g = __gcd(g, cur);
  37.         }
  38.     }
  39.  
  40.     if (g == 1) return 0;
  41.     int res = 1;
  42.     for (int i = 2; i * i <= g; ++i) {
  43.         int cnt = 0;
  44.         while (g % i == 0) {
  45.             ++cnt;
  46.             g /= i;
  47.         }
  48.         res *= cnt + 1;
  49.     }
  50.     if (n != 1) {
  51.         res *= 2;
  52.     }
  53.     return res - 1;
  54. }
  55.  
  56. inline void solve() {
  57.     cin >> n;
  58.     a.resize(n);
  59.     for (int i = 0; i < n; ++i) {
  60.         cin >> a[i];
  61.     }
  62.  
  63.     int ans = 0;
  64.     for (int i = 2; i <= ceil(sqrt(n)); ++i) {
  65.         if (n % i == 0) {
  66.             ans += get(i);
  67.             if (i != n / i) {
  68.                 ans += get(n / i);
  69.             }
  70.         }
  71.     }
  72.     cout << ans + 1 << '\n';
  73. }
  74.  
  75.  
  76. int32_t main() {
  77.     IOS;
  78.     clock_t tStart = clock();
  79.  
  80.     int tt = 1;
  81.     cin >> tt;
  82.     while (tt --> 0) {
  83.         solve();
  84.     }
  85. //    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment