QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585399#9376. GameSaviorWA 0ms3644kbC++201.1kb2024-09-23 20:39:242024-09-23 20:39:28

Judging History

你现在查看的是最新测评结果

  • [2024-09-23 20:39:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-09-23 20:39:24]
  • 提交

answer

#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
#define int long long
using ll = long long;
const int inf = 2e15+7, N = 3e5+5, mod = 998244353;
typedef pair<int, int> P;
int qpow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1) ans=ans*a%c;
        b>>=1,a=a*a%c;
    }
    return ans;
}
int x,y,a,b,c;
int ans=1;
void dfs(int x, int y, int cur) {
    if(x == y) {
        ans = (ans + cur * a) % mod; 
        return ;
    } else if(x < y) {
        int d = (y - 1) / x;
        dfs(x, y - d * x, cur * qpow(a, d,mod) % mod);
    } else {
        int d = (x - 1) / y;
        ans = (ans + cur * (1 - qpow(b, d,mod) + mod)) % mod;
        dfs(x - d * y, y, cur * qpow(b, d,mod) % mod);
    }
}
void solve(){
    cin>>x>>y>>a>>b>>c;
    int s=qpow(a+b,mod-2,mod);
    a=a*s%mod,b=b*s%mod;
    ans=1;
    dfs(x,y,1);
    cout<<ans<<endl;
    return;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int t = 1;cin>>t;
    while (t--)solve();
    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15

output:

499122178
910398851
220911477

result:

wrong answer 1st lines differ - expected: '499122177', found: '499122178'