QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751173 | #9622. 有限小数 | sixx_onee | WA | 0ms | 3652kb | C++20 | 1.7kb | 2024-11-15 17:22:41 | 2024-11-15 17:22:42 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int num[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;
}
int exgcd(int a,int b,int &x,int &y)
{
if(!b){x = 1,y = 0;return a;}
else
{
int d = exgcd(b,a%b,x,y);
int c = y;
y = x-a/b*y;
x = c;
return d;
}
}
void solve()
{
int c = 0x3f3f3f3f3f3f3f3f;
int a, b;
cin >> a >> b;
int p = b;
int ansd;
while (p % 2 == 0)
p /= 2;
while (p% 5 == 0)
p /= 5;
if(p==1){
cout << 0 << ' ' << 1 << endl;//p为1则c可以取到0
return;
}
for (int i = 1; i <= cnt; i++)
{
int d = num[i] * p;
if (d > 1e9)//遍历所有<=1e9的d
break;
int x,y,aq1;
aq1 = a*num[i];
exgcd(b/p,p,x,y);
x = -aq1*x;//现在x为qx+py = -aq1的解
x = (x%p+p)%p;//取最小正整数解
if(c>x)c = x,ansd = d;
}
cout << c << ' ' << ansd << endl;
}
signed main()
{
int tt = 1;
cin >> tt;
for (int i = 0; i <= 29; i++)
{
for (int j = 0; j <= 12; j++)
{
int cc = quik_power(2, i) * quik_power(5, j);
if (cc <= 1e9)
{
num[++cnt] = cc;
}
else
break;
}
}
// cout << cnt << endl;
while (tt--)
{
solve();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 1 4375 6 154296875
result:
wrong answer Jury found better answer than participant's 3 < 6 (Testcase 4)