QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#271134 | #5301. Modulo Ruins the Legend | arahato | WA | 0ms | 3372kb | C++14 | 1.1kb | 2023-12-01 23:48:11 | 2023-12-01 23:48:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
char c=getchar();bool f=0;x=0;
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f) x=-x;return x;
}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{if(x>9) write(x/10);putchar('0'+x%10);}
}
#define int __int128
int n,m,s,a,b,x,y;
int gcd(int x,int y){
return x?gcd(y%x,x):y;
}
int exgcd(int a,int b,int &x,int &y){
if(!b) return x=1,y=0,a;
int g;return g=exgcd(b,a%b,y,x),y-=a/b*x,g;
}
auto solve(int a,int b,int c){
int x,y,g;
g=exgcd(a,b,x,y);
if(c%g) return pair<int,int>{-1,-1};
x*=c/g;
x=(x%b+b)%b;
y=(c-a*x)/b;
return pair<int,int>{x,y};
}
signed main(){
read(n);read(m);
for(int i=1,x;i<=n;i++) read(x),s=(s+x)%m;
int A=n,B=n*(n+1)/2;
int g=gcd(A,B),ans=gcd(g,m);
pair<int,int> a=solve(g,m,ans-s);
pair<int,int> b=solve(A,B,(a.first+m*n)*g%m);
write(ans);puts("");
write(b.first%m);putchar(' ');write(b.second%m);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3372kb
input:
6 24 1 1 4 5 1 4
output:
3 0 1
result:
wrong answer Result not equal to solution.