QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741454#9622. 有限小数sixx_oneeWA 27ms3612kbC++201.7kb2024-11-13 14:24:242024-11-13 14:24:27

Judging History

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

  • [2024-11-13 14:24:27]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3612kb
  • [2024-11-13 14:24:24]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5+10;

int num[N],p[N],cnt;

long long quik_power(int base, int power)
{
	long long result = 1;   
	while (power > 0)           
	{
		if (power & 1)         							
			result = result * base;   
			//根据公式每个项都取余数后在再做累乘
		base = base * base ;   
			//根据公式每个项都取余数后在再做平方操作      						
		power >>= 1;         						
	}
			//根据公式在最后的的结果上再来一次取余数
	return result;       
}

void solve()
{
    int c = 0x3f3f3f3f3f3f3f3f;
    int a,b;cin >> a >> b;
    int x = b;
    int ansd=0;
    while(x%2==0)x/=2;
    while(x%5==0)x/=5;
    //a/b+c/d
    //ad+bc = kbd
    //c = (kbd-ad)/b
    //k*bd-ad>=0;
    //(k*bd-ad)/b = k*d-a(2^i*5^j)>=0
    //(k*b-a)(d/b);
    //k>=a/b
    //1<=1/k <=b/a

    for(int i = 1;i<=cnt;i++)
    {
        int d = num[i]*x;
        if(d>1e9)break;
        int j = lower_bound(num+1,num+1+cnt,b/a)-num;
        int k = num[j];
        // cout << d << ' ' << k << '|' << endl;
        if(a*d%b||d%k)continue;
        if(c>d/k-a*d/b)c = d/k-a*d/b,ansd = d;
    }
    if(c==0){cout << 0 << ' ' << 1 << endl;return;}
    cout << c << ' ' << ansd << endl;

}

signed main()
{
    int tt =1;
    cin >> tt;
    for(int i = 0;i<=29;i++)
    {
        for(int j = 0;j<=29;j++)
        {
            int cc = quik_power(2,i)*quik_power(5,j);
            if(cc<=1e9)
            {
                num[++cnt] = cc;
            }
            else break;
        }
    }
    sort(num+1,num+1+cnt);
    // cout << cnt << endl;
    while(tt--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 27ms
memory: 3584kb

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
25 53
-32768000 983040000
-6553600 917504000
11 1810
43 123
5 282
5 326
28 99
3 64
28 61
1 32
-12288000 999424000
-2621440 901775360
4 74
15 143
13 53
-52428800 964689920
1 31
1 6
9 362
18 91
10 23
10 81
0 1
3 190
43 160
17 166
22 151
65 153
4 58
3 19
-9011200 924057600
29 124
5 96
68 139
4 295...

result:

wrong answer Jury found better answer than participant's 1 < 25 (Testcase 2)