QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628680 | #5301. Modulo Ruins the Legend | Sound_Medium | WA | 7ms | 3704kb | C++23 | 1.7kb | 2024-10-10 21:38:40 | 2024-10-10 21:38:41 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
int s,d;
int xx,yy;
int exgcd(int a, int b, int &x, int &y)// 拓欧
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int d = exgcd(b, a % b, y, x);
y -= (a / b) * x;
return d;
}
int e;
void extend_gcd(int a, int b, int& d, int& x, int& y)
{
if(!b){ d = a; x = 1; y = 0; }
else { extend_gcd(b, a%b,d, y, x); y -= x*(a/b);}
}
void solve () {
cin>>n>>m;
int sum=0;
for(int i=1;i<=n;i++){
int x;
cin>>x;
sum+=x;
}
int a=n,b=(n+1)*n/2;
int k=gcd(a,b);
exgcd(a,b,s,d);
s=(s%m+m)%m;
d=(d%m+m)%m;
// extend_gcd(a,b,e,s,d);
// int b1=b/k;
// s=(s+b1)*(e/k);
// s=(s % b1 + b1) % b1;
// d=(e - a*s) / b;
int res=exgcd(k,m,xx,yy);
xx=(((-sum%m)/res*xx)%m+m)%m;
cout<<(((sum)%m+a*s*xx%m+b*d*xx%m)%m)<<endl;
cout<<(s*xx%m)<<" "<<(d*xx%m)<<endl;
// // work(a,b,(a*s+b*d)%m,s,d);
// cerr<<s<< " "<<d<<endl;
// int mi1=sum%m;
// if(mi1==0){
// cout<<0<<endl<<0<<" "<<0<<endl;
// return ;
// }
// int mi2=m-sum%m;
// if(mi2%k==0){
// cout<<0<<endl<<mi2/k*s<<" "<<mi2/k*d<<endl;
// return ;
// }
// else{
// mi2/=k;
// mi2=(sum+(mi2+1)*k)%m;
// if(mi1<=mi2){
// cout<<mi1<<endl<<0<<" "<<0<<endl;
// }
// else{
// cout<<mi2<<endl<< (mi2+1)*s<<" "<<(mi2+1)*d <<endl;
// }
// }
}
signed main () {
int T = 1;
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//cin>>T;
while (T --) solve ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
6 24 1 1 4 5 1 4
output:
1 15 19
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
1 1000000000 963837005
output:
0 0 36162995
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2 1 0 0
output:
0 0 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 1000000000 948507269 461613424
output:
0 410120693 589879307
result:
ok ok
Test #7:
score: 0
Accepted
time: 3ms
memory: 3644kb
input:
100000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0 0 0
result:
ok ok
Test #8:
score: -100
Wrong Answer
time: 7ms
memory: 3636kb
input:
100000 1000000000 253614966 278270960 980235895 498158918 928430170 216003119 852570558 948400590 239257296 897053667 294741176 38297441 382677590 406314557 609468973 854148232 314532767 738191551 158215002 5865825 920471826 380037058 356271728 749175327 28319049 208101105 953758995 896570758 521930...
output:
520736277 535950000 999989281
result:
wrong answer Result not equal to solution.