QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789565#9622. 有限小数youngerWA 31ms3620kbC++201.7kb2024-11-27 20:52:062024-11-27 20:52:07

Judging History

This is the latest submission verdict.

  • [2024-11-27 20:52:07]
  • Judged
  • Verdict: WA
  • Time: 31ms
  • Memory: 3620kb
  • [2024-11-27 20:52:06]
  • Submitted

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 solve()
{
    bm.clear();
    bm2.clear();
    ans=0;
    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});
    for(int i=0;i<bm.size();i++)
        if(bm[i].first!=2&&bm[i].first!=5)
        {
            goto label;
        }
    std::cout<<"0 1\n";
    return 0;
    label:dfs();
    for(int c=1;c<=b;c++)
    {
        dfs2(c);
        if(ans!=0)
        {
            std::cout<<c<<' '<<ans<<'\n';
            return 0;
        }
    }
    return 0;
}
signed main()
{
    int T;
    std::cin>>T;
    while(T--)
    {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

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: 31ms
memory: 3604kb

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
1 828125000
1 60
1 109375
1 231680000
23 960937500
1 36096000
5 326
1 63360
0 1
1 61000
0 1
1 4880
1 10750
1 18500
1 11714560
1 331250
1 898437500
1 31
1 6
1 289600000
1 455000
1 115000000
1 1265625
0 1
1 29687500
0 1
1 415
1 235937500
1 765000000
1 181250
1 2968750
1 4406250
3 24800
1 12000
3 ...

result:

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