Logo Wy Online Judge

WyOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386#52. 「NOIP2012」同余方程j27eGU10021ms3556kbC++23324b2025-04-23 11:34:132025-04-23 11:34:14

answer

#include<bits/stdc++.h>
using namespace std;
int exgcd(int a,int b,int &x,int &y)
{
	if(b==0)
	{
		x=1,y=0;
		return a;
	}
	else
	{
		int d=exgcd(b,a%b,x,y);
		int t=x-a/b*y;
		x=y,y=t;
		return d;
	}
}
int main()
{
	int a,b,x,y;
	cin>>a>>b;
	exgcd(a,b,x,y);
	while(x<0)x=x+b;
	cout<<x;
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 3ms
memory: 3540kb

input:

7 10


output:

3

result:

ok "3"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3212kb

input:

71 32

output:

23

result:

ok "23"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3216kb

input:

178 341

output:

182

result:

ok "182"

Test #4:

score: 10
Accepted
time: 4ms
memory: 3556kb

input:

233 1000

output:

897

result:

ok "897"

Test #5:

score: 10
Accepted
time: 1ms
memory: 3348kb

input:

137188 19982465

output:

2709667

result:

ok "2709667"

Test #6:

score: 10
Accepted
time: 3ms
memory: 3212kb

input:

26747 47232425

output:

23454633

result:

ok "23454633"

Test #7:

score: 10
Accepted
time: 1ms
memory: 3156kb

input:

86940520 376534211

output:

183549018

result:

ok "183549018"

Test #8:

score: 10
Accepted
time: 3ms
memory: 3192kb

input:

1420590574 1783828399

output:

1038716345

result:

ok "1038716345"

Test #9:

score: 10
Accepted
time: 3ms
memory: 3216kb

input:

1994182834 1487268523

output:

977649103

result:

ok "977649103"

Test #10:

score: 10
Accepted
time: 3ms
memory: 3288kb

input:

1121324517 2000000000

output:

1746511853

result:

ok "1746511853"