Source Code
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>

#include<cstring>
#include<sstream>
using namespace std;
long long  gcd(long long  a, long long  b) { return (a) ? gcd(b % a, a) : b; }
long long  lcm(long long  a, long long  b) { return (a * b) / gcd(a, b); }
int main() {
    std::ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    long long n,m,x,s=0,y;
    cin>>n>>m;
    y=gcd(n,m);
    for(int i=0;i<n;i++) {
        cin >> x;
        s=((s%y)+(x%y))%y;
    }
    long long ans=0;
    if(s==0)
    ans=(n*m)/lcm(n,m);
    cout<<ans;
}
Copy
Spin the wheel AyaHamza
GNU G++17
140 ms
324 KB
Runtime Error