QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#512883#9167. Coprime Arrayucup-team3591#WA 0ms1508kbC++141.1kb2024-08-10 16:10:122024-08-10 16:10:13

Judging History

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

  • [2024-08-11 17:38:28]
  • hack成功,自动添加数据
  • (/hack/775)
  • [2024-08-10 16:10:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1508kb
  • [2024-08-10 16:10:12]
  • 提交

answer

#include<cstdio>
typedef long long ll;
inline ll read(){
	ll x=0;
	int f=0,ch=0;
	while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
	while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
	return f?-x:x;
}
inline void write(ll x,char end=' '){
	if(x==0){
		putchar('0');
		putchar(end);
		return;
	}
	if(x<0) putchar('-'),x=-x;
	int ch[40]={0},cnt=0;
	while(x){
		ch[cnt++]=(int)(x%10);
		x/=10;
	}
	while(cnt--) putchar(ch[cnt]+48);
	putchar(end);
}
const int inf=1e9;
inline int gcd(int x,int y){
	if(x<0) x=-x;
	if(y<0) y=-y;
	return y==0?x:gcd(y,x%y);
}
int main(){
	int s=read(),x=read();
	if(gcd(s,x)==1){
		printf("1\n%d\n",s);
		return 0;
	}
	if(gcd(s-1,x)==1){
		printf("2\n1 %d\n",s-1);
		return 0;
	}
	if(s+1<=inf&&gcd(s+1,x)==1){
		printf("2\n-1 %d\n",s+1);
		return 0;
	}
	for(int i=2;;++i){
		if(gcd(s-i,x)==1){
			printf("%d\n",i+1);
			for(int j=1;j<=i;++j) putchar('1'),putchar(' ');
			write(s-i);
			return 0;
		}
		if(s+i<=inf&&gcd(s+i,x)==1){
			printf("%d\n",i+1);
			for(int j=1;j<=i;++j) putchar('-'),putchar('1'),putchar(' ');
			write(s+i);
			return 0;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 1488kb

input:

9 6

output:

3
1 1 7 

result:

ok Correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 1484kb

input:

14 34

output:

2
1 13

result:

ok Correct

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 1508kb

input:

1000000000 223092870

output:

4
1 1 1 999999997 

result:

wrong answer Jury's answer is better than participant's