QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#810099#9622. 有限小数Nana7#WA 43ms3656kbC++14876b2024-12-11 19:42:372024-12-11 19:42:46

Judging History

This is the latest submission verdict.

  • [2024-12-11 19:42:46]
  • Judged
  • Verdict: WA
  • Time: 43ms
  • Memory: 3656kb
  • [2024-12-11 19:42:37]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#define I inline
#define int long long
using namespace std;

I void exgcd(int a,int b,int &x,int &y){
	if(b==0) {
		x=1,y=0; 
		return ;
	}
	exgcd(b,a%b,x,y);
	int d=x;
	x=y,y=d-a/b*y;
} 
int gcd(int x,int y) {
	if(!y) return x;
	return gcd(y,x%y);
}
I void solve() {
	int a,b; cin>>a>>b;
	int rev=b;
	while(rev%2==0) rev/=2;
	while(rev%5==0) rev/=5;
	int ansc=1e9+1,ansd=0;
	for(int d=rev;d<=1e9;d*=2) {
		for(int nd=d;nd<=1e9;nd*=5) { //cout<<nd<<endl;
			int nk=0,nc=0,g=gcd(rev*rev,b),B=rev*rev/g,C=-a*d;
			if(C%g) continue;
			C/=g;
			exgcd(b/g,B,nc,nk);
			int mnc=(nc*C%B+B)%B;
			if(mnc<ansc) {
				ansc=mnc;
				ansd=nd;
			}
		}
	}
	cout<<ansc<<' '<<ansd<<endl;
}
/*
4
1 2
2 3
3 7
19 79

*/

signed main()
{
	int T; cin>>T;
	while(T--) {
		solve();
	}	
}

詳細信息

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 14
3 316

result:

ok 4 case(s)

Test #2:

score: -100
Wrong Answer
time: 43ms
memory: 3608kb

input:

10000
11 12
28 53
17 60
2 35
17 181
80 123
68 141
79 163
71 99
13 64
33 61
15 32
16 61
11 86
33 74
128 143
40 53
7 23
30 31
5 6
86 181
73 91
13 23
71 81
1 2
7 38
117 160
33 83
129 151
88 153
25 58
16 19
19 141
95 124
43 96
71 139
11 59
106 109
93 152
34 43
17 99
1 57
20 159
16 25
5 73
159 170
172 17...

output:

1 3
1 54272
1 6
1 7
31 2965504
23 3936
5 282
5 326
5 3168
0 1
1 31232
0 1
7 1998848
1 44032
2 37
15 143
5 444596224
1 2944
1 31
1 6
9 362
9 186368
5 23552
10 81
0 1
1 304
0 1
3 10878976
11 2473984
5 156672
2 29
1 608
1 72192
15 31
1 3
15 36438016
1 944
3 109
1 76
7 22016
1 6336
1 29184
19 2605056
0 ...

result:

wrong answer Jury found better answer than participant's 1 < 31 (Testcase 5)