QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739509#9622. 有限小数lingo12321#Compile Error//C++141.4kb2024-11-12 21:58:372024-11-12 21:58:41

Judging History

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

  • [2024-11-12 21:58:41]
  • 评测
  • [2024-11-12 21:58:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second

const ll inf = 1e18;

void exgcd(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1, y = 0;
        return;
    }
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}

ll EXGCD(ll a,ll b,ll c){   // ax+by==c 的最小正 x 解
    if(c<0) c+=(-(c/b)+1)*b;
    ll d=__gcd(a,b);
    if(c%d!=0) return inf;
    ll x0,y0;
    exgcd(a,b,x0,y0);
     alf=c/d,bta=(b/d);
    x0*=alf,y0*=alf;
    x0=(x0%bta+bta)%bta;
    return x0;
}

ll qpow(ll a, ll b){
    ll ret=1;
    while(b){
        if(b&1) ret*=a;
        a*=a;
        b>>=1;
    }
    return ret;
}

void slv(){
    ll a, b, A, B;
    scanf("%lld%lld", &a, &b);
    A = 1, B = b;
    while(B % 2 == 0) {
        A *= 2;
        B /= 2;
    }
    while(B % 5 == 0) {
        A *= 5;
        B /= 5;
    }
    pair<ll, ll> ans = make_pair(inf, inf);
    for(int x = 0; x <= 30; x ++) {
        for(int y = 0; y <= 10; y ++) {
        	if(B * qpow(2, x) * qpow(5, y) > 1e9) break;
            ll C = 1ll * a * qpow(2, x) * qpow(5, y);
            pair<ll, ll> c = make_pair(EXGCD(A, B, -C), B * qpow(2, x) * qpow(5, y));
            if(c.fr < ans.fr) ans = c;
        }
    }
    cout << ans.fr << ' ' << ans.sc << '\n';
    return;
}

int main(){
    int T;
    scanf("%d", &T);
    while(T --) slv();
}

/*

4
1 2
2 3
3 7
19 79

*/

Details

answer.code: In function ‘long long int EXGCD(long long int, long long int, long long int)’:
answer.code:24:6: error: ‘alf’ was not declared in this scope
   24 |      alf=c/d,bta=(b/d);
      |      ^~~
answer.code:24:14: error: ‘bta’ was not declared in this scope
   24 |      alf=c/d,bta=(b/d);
      |              ^~~
answer.code: In function ‘void slv()’:
answer.code:42:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |     scanf("%lld%lld", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:67:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~