QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588597 | #5301. Modulo Ruins the Legend | louhao088# | WA | 0ms | 3760kb | C++23 | 1.0kb | 2024-09-25 13:34:47 | 2024-09-25 13:34:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
inline int read(){
char ch=getchar();bool f=0;int x=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
inline void print(int x){
static int a[55];int top=0;
if(x<0) putchar('-'),x=-x;
do{a[top++]=x%10,x/=10;}while(x);
while(top) putchar(a[--top]+48);
}
int n,m,A,B,C,x,y;
int exgcd(int a,int b){
if(!b) {x=1,y=0;return a;}
int res=exgcd(b,a%b);
int t=x;x=y,y=t-a/b*y;
return res;
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++) {C+=read(); if(C>=m) C-=m;}
A=n%m,B=((1ll*n*(n-1))>>1)%m;
int s,t,p,q;
p=exgcd(A,m),s=(x%m+m)%m;
q=exgcd(B,m),t=(x%m+m)%m;
int r=exgcd(p,q);
x=(x%m+m)%m,y=(y%m+m)%m;
s=1ll*s*x%m,t=1ll*t*y%m;
int d=C/r;
s=(m-1ll*d*s%m)%m,t=(m-1ll*d*t%m)%m;
printf("%d\n",C%r);
printf("%d %d\n",s,t);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3760kb
input:
6 24 1 1 4 5 1 4
output:
1 0 15
result:
wrong answer Result not equal to solution.