QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737324#9622. 有限小数crychicWA 619ms3660kbC++171.6kb2024-11-12 15:29:432024-11-12 15:29:44

Judging History

This is the latest submission verdict.

  • [2024-11-12 15:29:44]
  • Judged
  • Verdict: WA
  • Time: 619ms
  • Memory: 3660kb
  • [2024-11-12 15:29:43]
  • Submitted

answer

#include<bits/stdc++.h>

using  namespace std;
using ll = long long;
ll dd;
void exgcd(ll a,ll b,ll &x,ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        dd = a;
        return ;
    }
    exgcd(b,a % b,y,x);
    y -= a / b * x;
}
map<ll,int> mp;
ll dfs_mod;
// (ad + bc) / bd (b * y + x * dfs_mod) == obj
ll ans = 1e18,ansd = -1;
ll a,b;
void dfs(ll nowd){
    if(mp.count(nowd))return ;
    if(nowd > 1e9) return ;
    mp[nowd] = 1;
    ll obj =(((- a * nowd) % dfs_mod) + dfs_mod) % dfs_mod;
    ll x,y;
    exgcd(b,dfs_mod,x,y);
    if(obj % dd == 0){
        ll k = obj / dd;
        ll res = ((k * x % dfs_mod) + dfs_mod) % dfs_mod;
        if(res < ans){
            ans = res;
            ansd = nowd;
        }
        // cout << dfs_mod << ' ' << k << ' ' << nowd << ' ' << res << ' ' << obj << '\n';
    }
    dfs(nowd * 2);
    dfs(nowd * 5);
}
void solve(){
    cin >> a >> b;
    vector<ll> facs;
    ans = 1e18;
    mp.clear();
    for(int i = 1;i * i <= b;i ++){
        if(b % i == 0){
            if(i % 2 != 0 && i % 5 != 0){
                facs.push_back(i);
            }
            int inv = b / i;
            if(inv != i && inv % 2 != 0 && inv % 5 != 0){
                facs.push_back(inv);
            }
        }
    }
    ll val = b;
    while(val % 2 == 0)val /= 2;
    while(val % 5 == 0) val /= 5;
    for(auto fac : facs){
        dfs_mod = val * fac;
        dfs(fac);
    }
    cout << ans << ' ' << ansd << '\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t --){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 619ms
memory: 3660kb

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 3
1 54272
7 6
3 146800640
1 231680000
23 3936
1 36096000
5 326
1 633600000
0 1
1 31232
0 1
1 4880
967 172
721 2424832
1 11714560
1 53000000
1 2944
1 31
7 6
1 289600000
1 455000
1 120586240
1 331776000
0 1
199 77824
0 1
1 25937500
1 19328000
1 765000000
449 118784
1 608
1 72192
24 203161600
7 3
3 3...

result:

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