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;
    cin>>n>>m;
    for(int i=0;i<n;i++) {
        cin >> x;
        s+=x;
    }
    long long ans=0;
    if(s%gcd(n,m)==0)
    ans=(n*m)/lcm(n,m);
    cout<<ans;
}
Copy
Spin the wheel AyaHamza
GNU G++17
112 ms
256 KB
Wrong Answer