QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788437 | #9622. 有限小数 | O_start | WA | 1ms | 3512kb | C++20 | 3.5kb | 2024-11-27 16:56:02 | 2024-11-27 16:56:03 |
Judging History
answer
#pragma oucGCC optimize(2)
#include<iostream>
#include<queue>
#include<cmath>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<stack>
#include<map>
#include<unordered_map>
using namespace std;
__int128 k, p, q, m, n;
const int maxn = 200005;
const long long inf = 0xfffffffffffffff;
const long long mod = 998244353;
int t;
string s;
vector<__int128>rec;
__int128 read(){
__int128 x=0;bool f=0;char c=getchar();
while (c<'0'||c>'9'){if (c=='-')f=1;c=getchar();}
while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return f?-x:x;
}
inline void write(__int128 x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
long long fact[maxn], infact[maxn];
__int128 qpow(__int128 a, __int128 b) {
if (b < 0) return 0;
__int128 ans = 1;
while (b) {
if (b & 1) ans = (ans * a);
b >>= 1;
a = (a * a);
}
return ans;
}
void init() {
fact[0] = 1, infact[0] = 1;
for (int i = 1; i < maxn; i++) {
fact[i] = i * fact[i - 1] % mod;
infact[i] = infact[i - 1] % mod * qpow(i, mod - 2) % mod;
}
}
long long inv(long long n) {
return qpow(n, mod - 2);
}
long long frac_mod(long long a, long long b) {
return (a * inv(b) % mod) % mod;
}
long long nCr(long long n, long long r) {
if (r > n || r < 0)
return 0;
if (n == r)
return 1;
if (r == 0)
return 1;
return (fact[n] * infact[r]) % mod * infact[n - r] % mod;
}
__int128 gcd(__int128 da, __int128 xiao) {
while (xiao != 0) {
__int128 temp = xiao;
xiao = da % xiao;
da = temp;
}
return(da);
}
__int128 lcm(__int128 da, __int128 xiao) {
return da*xiao/gcd(da,xiao);
}
__int128 Ceil(__int128 n,__int128 k){//重写向上取整
__int128 ans=n/k;
if(n%k!=0)ans++;
return ans;
}
int main(){
for(int i=0;i<=63;i++){
for(int j=0;j<=27;j++){
__int128 tmp=qpow(2,i)*qpow(5,j);
if(tmp<=1e18){
rec.push_back(tmp);
}
else{
break;
}
}
}
cin>>t;
while(t--){
n=read();
m=read();
pair<__int128,__int128>ans={inf,inf};
for(auto k:rec){
__int128 tmp=lcm(k,m);
__int128 tmp2=tmp/m*n;//a
__int128 tmp3=tmp/k;//约多少
__int128 tmp4=Ceil(tmp2,tmp3);
//cout<<tmp<<" "<<tmp2<<" "<<tmp3<<" "<<tmp4<<" "<<tmp4*tmp3-tmp2<<'\n';
__int128 tmpans=tmp4*tmp3-tmp2;
__int128 g=gcd(tmpans,tmp2);
tmpans/=g;
tmp/=g;
if(tmpans<ans.first&&tmp<=1e9){
ans.first=tmpans;
ans.second=tmp;
}
}
// __int128 tmp1=lcm(m,ans.second);
// __int128 tmp2=tmp1/m*n+tmp1/ans.second*ans.first;
// __int128 tmp3=gcd(tmp1,tmp2);
// tmp1/=tmp3;
// tmp2/=tmp3;
// while(tmp1%2==0){
// tmp1/=2;
// }
// while(tmp1%5==0){
// tmp1/=5;
// }
// if(tmp1!=1){
// cout<<"wa: "<<a1<<" "<<b1<<'\n';
// }
write(ans.first);
putchar(' ');
write(ans.second);
putchar('\n');
//cout<<ans.first<<" "<<ans.second<<'\n';
}
return 0;
}
/*
4
1 2
2 3
3 7
19 79
*/
/*
42 18468
6335 26501
19170 15725
11479 29359
26963 24465
5706 28146
23282 16828
2996 11943
32392 14605
17422 18717
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3512kb
input:
4 1 2 2 3 3 7 19 79
output:
0 2 1 3 1 291 3 316
result:
wrong answer The result is not terminating.(Testcase 3)