QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741827#9622. 有限小数kekeWA 48ms3692kbC++201.1kb2024-11-13 15:18:412024-11-13 15:18:42

Judging History

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

  • [2024-11-13 15:18:42]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:3692kb
  • [2024-11-13 15:18:41]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>

template <typename T> inline void read(T &s)
{
    s=0;int f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())s=s*10+ch-'0';
    s*=f;
}

#define ll long long

ll Gcd(ll a,ll b){return !b?a:Gcd(b,a%b);}
void exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)return x=1,y=0,void();
    exgcd(b,a%b,y,x);
    y-=a/b*x;
}
ll solve(ll a,ll b,ll c)
{
    if(!c)return 0;
    ll x0=0,y0=0;
    exgcd(a,b,x0,y0);
    x0=(x0%b+b)%b;
    x0=x0*c%b;
    return x0;
}

const ll Lim=1e9;

void work()
{
    ll a,b;read(a);read(b);
    ll k1=1;
    while(!(b%2))k1*=2,b/=2;
    while(!(b%5))k1*=5,b/=5;
    ll ansc=b-a,ansd=b;
    for(ll tmp=1;tmp*b<=Lim;tmp*=2)
    for(ll k2=tmp;k2*b<=Lim;k2*=5)
    {
        //printf("k2=%lld\n",k2);
        ll g=Gcd(k1,k2);
        ll c=solve(k1/g,b,(b-k2/g*a%b)%b);
        //if(k2==2)printf("!%lld\n",c);
        if(ansc>c)ansc=c,ansd=k2*b;
    }
    printf("%lld %lld\n",ansc,ansd);
}

int main()
{
    int T;read(T);
    while(T--)work();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 4375
3 316

result:

ok 4 case(s)

Test #2:

score: -100
Wrong Answer
time: 48ms
memory: 3648kb

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:

-8 3
1 828125000
-14 3
1 7
1 231680000
23 960937500
1 36096000
5 326
1 63360
-12 1
1 61000
-14 1
1 4880
1 10750
1 18500
1 11714560
1 331250
1 898437500
1 31
-2 3
1 289600000
1 455000
1 115000000
1 1265625
0 1
1 1484375
-116 1
1 415
1 235937500
1 765000000
1 181250
1 2968750
1 4406250
-64 31
-40 3
3 ...

result:

wrong answer Integer -8 violates the range [0, 10^9]