QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747737#9622. 有限小数guodong#WA 0ms3796kbC++171.1kb2024-11-14 18:03:122024-11-14 18:03:12

Judging History

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

  • [2024-11-14 18:03:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2024-11-14 18:03:12]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(x, l, r) for(int x = l; x <= r; x++)
using namespace std;
typedef long long ll;
int pw2[105], pw5[105];

const int INF = 0x3f3f3f3f;
const ll XX = 1ll << 55;

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        int a, b, res = 1;
        scanf("%d%d", &a, &b);
        while(b % 2 == 0){
            res *= res * 2;
            b /= 2;
        }
        while(b % 5 == 0){
            res *= res * 5;
            b /= 5;
        }
        // printf(" %d %d\n", a, b);
        int ans = INF;
        ll s = 1, ans2;
        rep(i, 0, 60){
            ll ss = s;
            rep(j, 0, 60){
                if((b - (ss % b * a) % b) % b < ans){
                    ans = (b - (ss % b * a) % b) % b;
                    ans2 = res * ss * b;
                }
                // ans = max((ll)ans, ss % b);
                if(res * b * ss * 5 > INF) break;
                ss = ss * 5;
            }
            if(res * b * ss * 2 > INF) break;
            s = s * 2;
        }
        printf("%d %lld\n", ans, ans2);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 2
1 3
1 4375
6 154296875

result:

wrong answer Jury found better answer than participant's 3 < 6 (Testcase 4)