QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738091#9622. 有限小数BingeWA 0ms3996kbC++231.4kb2024-11-12 17:41:532024-11-12 17:41:54

Judging History

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

  • [2024-11-12 17:41:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3996kb
  • [2024-11-12 17:41:53]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
using i64 = long long;
using d128 = long double;
using  i128 = __int128_t;
 
void breakdown(i64 x, std::vector<int> &result) {
    for (int i = 2; i <= x / i; i ++)
        if (x % i == 0) {
            result.push_back(i);
            while(x % i == 0) x /= i;
        }
    if (x > 1) result.push_back(x);
}

void solve() {
    i64 a, b;
    std::cin >> a >> b;

    std::vector<int> bs;
    breakdown(b, bs);
    bool flag = true;
    for (auto i : bs) {
        if (i != 2 && i != 5) {
            flag = false;
            break;
        }
    }

    if (flag) {
        std::cout << 0 << ' ' << b << '\n';
        return;
    }
    int c=1e9,d=0;
    for(int i=0;i<=13;i++)
    {
        for(int j=0;j<=30;j++)
        {
            i128 ans=pow(2,j)*pow(5,i);
            if(ans>1e9)break;
            if((i128)ans*b>1e9)break;
            c=min(c,(int)(b-((ans*a)%b)));
            if(c==1)
            {
                cout<<1<<' '<<(int)ans*b<<endl;
                return;
            }
            d=ans*b;
        }
    }
    cout<<c<<' '<<d<<endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int T;
    std::cin >> T;
    while (T --) {
        solve();
    }

    return 0;
}

详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 2
1 3
1 14
3 771484375

result:

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