QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#763798#9622. 有限小数xdz_WA 0ms3600kbC++141.0kb2024-11-19 22:07:522024-11-19 22:07:52

Judging History

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

  • [2024-11-19 22:07:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2024-11-19 22:07:52]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define int long long 
#define se second
#define fi first 
#define endl '\n'
const int N = 1e5 + 10;

bool pan(int x){
	while(x % 2 == 0) x /= 2;
	while(x % 5 == 0) x /= 5;
	if(x == 1) return 1;
}

void solve(){
	int a,b;
	cin>>a>>b;
	int w = pan(b);
	if(w == 1){
		cout<<"0 1"<<endl;
		return ;
	}
	int ma = 1e9 / b;
	int er = 1;
	set<int> res1;
	while(er < ma){
		int wu = 1;
		for(int i = 0;i <= 100;i ++){
			if(i > 0) wu *= 5;
			int k = er * wu;
			if(k > ma) break;
			else res1.insert(k);
		}
		er *= 2;
	}
	vector<int> res;
	for(auto k : res1) res.push_back(k);
	int c = b - a,d = b;
//	cout<<c<<endl;
	for(auto x : res){
		int jian = a * x;
		int k = jian / b;
		if(k * b < jian) k ++;
		if(b * k - jian < c){
			c = b * k - jian;
			d = x * b;
//			cout<<x<<" "<<b<<endl;
		}
	}
	cout<<c<<" "<<d<<endl;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	solve();
	return 0;
}

详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
0 1
0 1
0 1

result:

wrong answer The result is not terminating.(Testcase 2)