QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608045#9381. 502 Bad GatewaySatonWA 0ms3616kbC++201.7kb2024-10-03 18:03:152024-10-03 18:03:16

Judging History

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

  • [2024-10-03 18:03:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-10-03 18:03:15]
  • 提交

answer

///by Saton.
#include<bits/stdc++.h>
#define PI acos(-1)
#define fi first
#define se second 
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define LL long long
#define ll __int128
#define DD double double
#define LD long double
#define rep(i,a,b) for(LL i = (a);i <= (b);i ++)
#define lep(i,a,b) for(LL i = (a);i >= (b);i --)
#define FLUSH fflush(stdout)
using namespace std;
const int N = 2e5 + 10,mod =  998244353,P = 131;
const LL inf = 1e9+10,INF = 1e18+10;
typedef pair<int,int> PII;
typedef pair<LL,int> PLI;
LL qmi(LL a,LL b,LL p) {LL res = 1;while(b) {if(b&1) res = (LL)res*a%p;a = (LL)a*a%p;b >>= 1;}return res%p;}
LL x,y,a0,a1,a,b,p0,p1;
LL ans1,ans2;

void dfs(LL x,LL y,LL p) {
    // cout << x << " " << y << " " << p << '\n';
    if(x==y) {
        ans1 = (ans1 + p0*p%mod) % mod;
        ans2 = (ans2 + p1*p%mod) % mod;
        return;
    }
    else if(x>y) {
        LL t = (x-1)/y;
        LL pr = qmi(p1,t,mod);
        ans1 = (ans1 + p*(1-pr+mod)%mod) % mod;
        x -= y*t;
        p = p*pr%mod;
        dfs(x,y,p);
    }
    else {
        LL t = (y-1)/x;
        LL pr = qmi(p0,t,mod);
        ans2 = (ans2 + p*(1-pr+mod)%mod) % mod;
        y -= x*t;
        p = p*pr%mod;
        dfs(x,y,p);        
    }
}

void solve() {
    cin >> x >> y >> a0 >> a1 >> b;
    a = (a0+a1)%mod;
    p0 = a0*qmi(a,mod-2,mod);
    p1 = a1*qmi(a,mod-2,mod);
    
    ans1 = ans2 = 0;
    dfs(x,y,1);
    
    cout << ans1 << '\n';
} 

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while(T --) { 
        solve();
    }
    // solve();
       
    return 0;
}  
/*   /\_/\
*   (= ._.)
*   / >  \>
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2
3

output:

1
1
1

result:

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