QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699963 | #5301. Modulo Ruins the Legend | tsogsummit# | RE | 0ms | 3676kb | C++14 | 1.3kb | 2024-11-02 11:23:32 | 2024-11-02 11:23:33 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
ll gcd(ll a, ll b) {
if(b == 0)
return a;
return gcd(b, a % b);
}
ll binpow(ll a, ll b , int mod) {
ll res = 1;
a %= mod;
while(b > 0) {
if(b & 1){
res = res * a;
res %= mod;
}
a = a * a;
a %= mod;
b >>= 1;
}
return res % mod;
}
int main(){
long long n , m , i;
cin >> n >> m;
long long sum = 0 , a;
for(i = 0 ; i < n ; i ++){
cin >> a;
sum += a;
}
long long k = gcd(gcd(n , n*(n + 1)/ 2) , m);
long long res = sum % k;
cout << res << '\n';//hariu;
long long resres;
if(gcd(n , m) == k){
resres = binpow(n/k , m/k-1 , m/k);
res -= sum;
while(res < 0)res += m;
res /= (resres * n % m);
cout << resres * res << " 0";
}
else {
resres = binpow(n*(n + 1)/2/k, m/k - 1 , m/k);
res -= sum;
while(res < 0)res += m;
res /= (resres *n *(n + 1) / 2 % m);
cout << "0 " << resres * res<< ' ';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
6 24 1 1 4 5 1 4
output:
1 0 21
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: -100
Runtime Error
input:
1 1 0