QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107070 | #5301. Modulo Ruins the Legend | shihoghmean | RE | 2ms | 3404kb | C++14 | 1.6kb | 2023-05-20 10:32:17 | 2023-05-20 10:32:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int __int128
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define py puts("Yes")
#define pn puts("No")
#define pt puts("")
#define pb push_back
#define wt(x) write(x),puts("")
#define wr(x) write(x) ,putchar(' ')
#define tx printf("fds")
#define mp make_pair
#define fi first
#define se second
inline int read(){
int x=0,k=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') k=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+ch-48;
ch=getchar();
}
return x*k;
}
void write(int x){
if(x<0){
x=-x;
putchar('-');
}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int power(int x,int y,int mod){
int num=1;
while(y){
if(y&1) num=(num*x)%mod;
x=x*x%mod;
y>>=1;
}
return num;
}
int mul(int x,int y,int mod){
int num=0;
while(y){
if(y&1) num=(num+x)%mod;
x=(x+x)%mod;
y>>=1;
}
return num;
}
const int N=1e6+7,mod=998244353;
int n,m,tot,cnt,ans,k;
int a[N],b[N];
char s[N];
int exgcd(int a,int b,int &x,int &y){
if(b==0){
x=1;
y=0;
return a;
}
int g=exgcd(b,a%b,x,y);
int tmp=x;
x=y;
y=tmp-a/b*y;
return g;
}
signed main(){
n=read();m=read();
int x=(1+n)*n/2,y=n,z=0;
fo(i,1,n) a[i]=read(),z+=a[i];
x%=m;
z%=m;
y%=m;
int X=0,Y=0;
int gg=exgcd(x,y,X,Y);
int ggg=exgcd(gg,m,X,Y);
k=(m-z)%m;
k=((k-1)/ggg+1)*ggg;
wt((k+z)%m);
int ppp=exgcd(gg,m,X,Y);
Y=(-Y)*(k/ppp);
int o=Y*m+k;
ppp=exgcd(x,y,X,Y);
X%=m;
Y%=m;
X=X*(o/ppp)%m;
Y=Y*(o/ppp)%m;wr((Y+m)%m);
wr((X+m)%m);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3384kb
input:
6 24 1 1 4 5 1 4
output:
1 15 3
result:
ok ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3404kb
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