QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107069#5301. Modulo Ruins the LegendshihoghmeanWA 0ms3416kbC++141.6kb2023-05-20 10:30:072023-05-20 10:30:11

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-20 10:30:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3416kb
  • [2023-05-20 10:30:07]
  • 提交

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((X+m)%m);wr((Y+m)%m);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3416kb

input:

6 24
1 1 4 5 1 4

output:

1
3 15 

result:

wrong answer Result not equal to solution.