QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789522 | #9622. 有限小数 | Texcavator# | WA | 0ms | 3588kb | C++23 | 1.4kb | 2024-11-27 20:40:17 | 2024-11-27 20:40:21 |
Judging History
answer
#include<iostream>
#include<vector>
#include<cmath>
#define int long long
int a,b;
std::vector<std::pair<int,int> > bm;
std::vector<int> bm2;
int ans=0;
void dfs(int now=0,int mul=1)
{
if(now==bm.size())
{
bm2.push_back(mul);
return ;
}
for(int i=0;i<=bm[now].second;i++)
{
dfs(now+1,mul);
mul*=bm[now].first;
}
}
int ml[2]={2,5};
void dfs2(int c,int now=0,int mul=1)
{
if(ans!=0) return ;
if(now==2)
{
for(int i=0;i<bm2.size();i++)
{
if((c*bm2[i]+a*mul)%b==0)
{
if(b*mul/bm2[i]<=1000000000)
{
ans=b*mul/bm2[i];
return ;
}
}
}
return ;
}
while(mul<=1000000000)
{
dfs2(c,now+1,mul);
if(ans!=0) return ;
mul*=ml[now];
}
}
signed main()
{
std::cin>>a>>b;
int x=b;
for(int i=2;i<=sqrt(x);i++)
{
if(x%i==0) bm.push_back({i,0});
while(x%i==0)
{
bm[bm.size()-1].second++;
x/=i;
}
}
if(x!=1) bm.push_back({x,1});
dfs();
for(int c=1;c<=b;c++)
{
dfs2(c);
if(ans!=0)
{
std::cout<<c<<' '<<ans;
return 0;
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
4 1 2 2 3 3 7 19 79
output:
1 1
result:
wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)