Source Code
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")

long long gcd(long long a, long long b){
        if(b == 0)
                return a;
        
        return gcd(b, a % b);
}
int main(){
        cin.tie(0);
        cin.sync_with_stdio(0);
        
        long long n, m;
        cin>>n>>m;
        
        long long sum = 0;
        long long a[n];
        for(int i = 0; i < n; i++){
                cin>>a[i];
        }
        for(int i = 0; i < n; i++){
                int j = (i - 1 + n) % n;
                long long d = a[i] - (a[j]);
                
                sum += d % n;
                sum %= n;
                if(sum < 0) sum += n;
                
        }
        if(sum == 0){
                cout<<gcd(m, n)<<"\n";
        }else{
                cout<<"0\n";
        }
}
Copy
Spin the wheel maghrabyJr_
GNU G++17
1 ms
216 KB
Wrong Answer