QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740274#9622. 有限小数KomorebieWA 22ms3824kbC++171.1kb2024-11-13 08:17:092024-11-13 08:17:09

Judging History

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

  • [2024-11-13 08:17:09]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:3824kb
  • [2024-11-13 08:17:09]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<ll>p;
unordered_map<ll, bool>f;
ll T;

bool check(ll x)
{
    while(x%2==0)x/=2;
    while(x%5==0)x/=5;
    return x==1;
}

void solve()
{
    ll a, b, c, ans = LLONG_MAX, max_z, max_y;
    cin>>a>>b;
    if(check(b))
    {
        cout<<0<<" "<<1<<endl;
        return;
    }
    for(int i = 0;i<p.size();i++)
    {
        ll y = p[i];
        ll z = y*a/b + 1;
        c = z*b - y*a;
        if(c<ans)
        {
            ans = c;
            max_z = z;
            max_y = y;
        }
    }
    ll L1 = max_z*b - max_y*a, L2 = max_y*b;
    ll d = max_y*b/__gcd(L1, L2);
    ll t = __gcd(ans, d);
    cout<<ans/t<<" "<<d/t<<endl;
}

void dfs(ll x)
{
    if(x<=1e15)
    if(!f[x]){
        f[x] = 1;
        p.push_back(x);
        dfs(2*x);
        dfs(5*x);
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int tt;
    cin>>tt;
    dfs(1);
    while(tt--)
    {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3824kb

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: 22ms
memory: 3528kb

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 12
1 54272
1 6
3 560
1 19434727014400000
23 3936
1 378493992960
1 17091788800000000
1 6803228196864000
0 1
1 31232
0 1
1 4093640704
1 10750
1 451660156250
1 122836064665600000
1 14227079168
1 2944
1 31
1 6
1 24293408768000000
1 31267361914880000
1 505775348776960
1 86973087744
0 1
1 152
0 1
1 1114...

result:

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