QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#271138 | #5301. Modulo Ruins the Legend | arahato | WA | 1ms | 3384kb | C++14 | 1.1kb | 2023-12-01 23:51:00 | 2023-12-01 23:51:00 |
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);
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: 1ms
memory: 3384kb
input:
6 24 1 1 4 5 1 4
output:
3 12 17
result:
wrong answer Result not equal to solution.