QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740878#9622. 有限小数zjhhhzjWA 28ms11564kbC++171016b2024-11-13 12:01:132024-11-13 12:01:13

Judging History

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

  • [2024-11-13 12:01:13]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:11564kb
  • [2024-11-13 12:01:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod (998244353)
#define PI 3.14159265358979323846
#define PII pair<ll,ll>
#define F first
#define S second
#define N 1000010
#define pb push_back
ll n,m;
vector<ll>vt;
void init(ll x) {
    vt.pb(x);
    if(x*2<=1e9)init(x*2);
    if(x*5<=1e9)init(x*5);
}
void solve() {
    cin>>n>>m;
    auto it=*(lower_bound(vt.begin(),vt.end(),m));
    //cout<<it<<'\n';
    if(it==m){
    	cout<<"0 1\n";return;
	}
    ll c=m-n,c25;
    for(auto x:vt) {
        if(m*x>1e9)break;
        ll ans=(x*n)%m;
        if(ans)ans=m-ans;
        if(ans<c) {
            c=ans;
            c25=x*m;
        }
        if(!c)break;
    }
    cout<<c<<' '<<c25<<'\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int _ = 1;
    
    init(1);
    sort(vt.begin(),vt.end());
    
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}
/*
4
1 2
2 3
3 7
19 79
*/

详细

Test #1:

score: 0
Wrong Answer
time: 28ms
memory: 11564kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 140698504728760
1 14
3 316

result:

wrong answer Integer 140698504728760 violates the range [1, 10^9]