QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#644629 | #9376. Game | Scene# | WA | 184ms | 3916kb | C++14 | 1.0kb | 2024-10-16 14:52:21 | 2024-10-16 14:52:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int read(){
int ret=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while( isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch&15);ch=getchar();}
return ret*f;
}
int T;
int p0,p1,a1,a2,b;
int quick_pow(int a,int b){
int ret=1;
while(b){
if(b&1) ret=1ll*ret*a%mod;
a=1ll*a*a%mod;b>>=1;
}
return ret;
}
int f(int A,int B){
if(A==0) return 0;
if(B==0) return 1;
if(A>B){
return (1ll*quick_pow(p0,A/B)*f(A%B,B)%mod+1ll*p0*(quick_pow(p1,A/B)-1)%mod*quick_pow(p1-1,mod-2)%mod)%mod;
}else if(B>A){
return 1ll*quick_pow(p0,B/A)*f(A,B%A)%mod;
}else{
return p0;
}
}
int main(){
T=read();
while(T--){
int A=read(),B=read();
a1=read(),a2=read(),b=read();
if(a1==0){
printf("0\n");
continue;
}
if(a2==0){
printf("1\n");
continue;
}
p0=1ll*a1*quick_pow(a1+a2,mod-2)%mod;
p1=1ll*a2*quick_pow(a1+a2,mod-2)%mod;
printf("%d\n",f(A,B));
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
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: 56ms
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: 184ms
memory: 3916kb
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:
259429845 304012676 276004583 244320957 865361324 89974363 740861943 409382391 106586727 163811004 359244270 712311081 67666920 406366192 169617618 413930200 48153864 676083358 574716942 875180692 532553364 688609036 169995291 704315617 501310681 456469851 424096417 649077780 332832529 135508162 120...
result:
wrong answer 1st lines differ - expected: '623291477', found: '259429845'