QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#582222 | #9376. Game | KULIANLEN# | WA | 93ms | 3888kb | C++14 | 1.0kb | 2024-09-22 15:42:07 | 2024-09-22 15:42:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int pi=998244353;
int ksm(int a,int b){
int res=1;
while(b){
if(b&1)res=res*a%pi;
a=a*a%pi;b>>=1;
}
return res;
}
int sa,sb,pa,pb,bi;
int gcd(int a,int b){
swap(pa,pb);
// printf("[%d %d]\n",a,b);
// if(a<b)return (pi+1-gcd(b,a))%pi;
if(b==0)return 0;
int p=a/b;
p=ksm(pa,p);
int c=a%b;
// printf("(%d %d)\n",p,c);
int p1=(1+pi-gcd(b-c,c))%pi;
// printf("(%d %d %d)%d\n",pa,pb,p1,(pa+pb*p1%pi)%pi);
return (p*(pa+pb*p1%pi)%pi)%pi;
}
void solve(){
scanf("%lld%lld%lld%lld%lld",&sa,&sb,&pa,&pb,&bi);
if(pa==0){printf("0\n");return ;}
if(pb==0){printf("1\n");return ;}
bi=pa+pb;bi=ksm(bi,pi-2);
swap(sa,sb);
swap(pa,pb);
pa=pa*bi%pi;pb=pb*bi%pi;
// printf("(%d %d)\n",pa,pb);
printf("%lld\n",(gcd(sa,sb)%pi+pi)%pi);
}
signed main(){
int t;scanf("%lld",&t);
for(int i=1;i<=t;i++)
solve();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
input:
3 1 1 2 2 6 1 3 2 3 6 3 4 7 3 15
output:
499122177 910398850 220911476
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 50ms
memory: 3792kb
input:
100000 1 1000000000 12980050 128257807 266126484 1 1000000000 400255084 123438563 768881284 1000000000 1000000000 24563487 72082135 450057094 1 1000000000 56952077 40876000 193815114 1000000000 1000000000 82048274 239365585 326520865 1000000000 1 309821265 346013425 963168258 1 1 104158269 199365020...
output:
947058399 376449942 612621163 138416357 592200562 45779380 870227707 169499045 86396463 415694940 46851356 951368934 426243016 864656779 750317399 922456360 486881524 824329239 198191519 189360084 966510181 512645443 695650039 703100783 550002158 438470182 246877045 39876086 667870434 405196653 5935...
result:
ok 100000 lines
Test #3:
score: -100
Wrong Answer
time: 93ms
memory: 3872kb
input:
100000 167959139 481199252 18199423 25950409 149762920 773386884 579721198 16629525 28339910 152155823 2087506 268792718 43528658 6471925 90197530 691952768 717268783 516613092 94328992 743662288 45277106 856168102 309821265 346013425 963168258 279198849 527268921 30167950 166388455 577970339 140515...
output:
776325618 168264045 197843910 673590782 623898779 434604104 423273231 763985242 900404804 66932027 434744334 481531844 231794874 735825242 625390671 37343296 644403072 217960486 932442686 759302952 517669324 586484676 416536795 236954318 416282544 334330557 132939661 429119414 867914189 124703366 36...
result:
wrong answer 1st lines differ - expected: '623291477', found: '776325618'