QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581380 | #9376. Game | Asbeforezb | WA | 282ms | 3712kb | C++20 | 1.4kb | 2024-09-22 12:23:57 | 2024-09-22 12:23:57 |
Judging History
answer
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define endl "\n"
//#define int long long
#define ll long long
#define db double
#define ull unsigned long long
const int N = 100000+10;
const int inf = 2147483647;
const int mod = 998244353;
using namespace std;
ll ksm(ll a,ll b) {
ll ans = 1;
while (b){
if (b&1) ans = ans*a%mod;
a = a*a%mod;
b >>= 1;
}
return ans%mod;
}
void solve() {
ll x,y,a0,a1,b;
cin >> x >> y >> a0 >> a1 >> b;
b = a0+a1;
ll ans = 0,pro = 1;
while (x&&y){
if (x >= y){
ll cnt1 = x/y,cnt2 = x%y;
ll tmp = ksm(a1,cnt1)%mod*ksm(ksm(b,cnt1),mod-2)%mod;
tmp = (1-tmp+mod)%mod;
tmp = pro*tmp%mod;
ans = (ans+tmp)%mod;
pro = pro*tmp%mod;
x = cnt2;
}
else{
ll cnt1 = y/x,cnt2 = y%x;
ll tmp = ksm(a0,cnt1)%mod*ksm(ksm(b,cnt1),mod-2)%mod;
if (cnt2 == 0){
ans = (ans+tmp*pro%mod)%mod;
break;
}
pro = pro*tmp%mod;
y = cnt2;
}
}
cout << ans << endl;
}
int main() {
cout << fixed << setprecision(8);
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 58ms
memory: 3712kb
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: 282ms
memory: 3632kb
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:
655518745 625877807 650942605 347342637 165058168 175676655 240862142 447748100 238914176 976892175 342945187 305984447 832641882 153852315 869694320 325930016 688490772 654232848 171424174 901339168 80509157 406701748 904749402 257918684 751647536 628396567 555232841 891260001 707962526 914484141 2...
result:
wrong answer 1st lines differ - expected: '623291477', found: '655518745'