样例过了0分求调
查看原帖
样例过了0分求调
1032325
sunrainblue楼主2024/10/3 21:18
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll P1 = 399999999;
const ll P2 = 400000000;
const ll MOD = P1 * P2;
ll t, rmd1, rmd2;
void exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b){
        x = 1, y = 0;
        return;
    }
    exgcd(b, a % b, x, y);
    ll t = x;
    x = y, y = t - (a / b) * y;
}
ll op(ll r1, ll r2) {
	ll ans = 0;
    ll x = 0, y = 0;
    exgcd(P2, P1, x, y);
    if(x<0)
        x += P1;
    ans =(ans + P2 * x * r1 % MOD) % MOD;
    //cout << ans << endl;
    x = 0, y = 0;
    exgcd(P1, P2, x, y);
    if(x<0)
        x += P2;
    ans =(ans + P1 * x * r2 % MOD) % MOD;
    //cout << ans << endl;
    return ans;
}
int main() {
    scanf("%lld", &t);
    while (t--) {
        printf("? %lld\n", P1);
        cout << endl;
        scanf("%lld", &rmd1);
        //cout << rmd1 << " " << endl;
        if(rmd1 == -1) {
            return 0;
        }
        printf("? %lld\n", P2);
        cout << endl;
        scanf("%lld", &rmd2);
        if(rmd2 == -1) {
            return 0;
        }
        //cout << rmd2 << " " << endl;
        if (rmd1 == rmd2) {
            printf("! %lld\n", rmd1);
            cout << endl;
        }else{
            printf("! %lld\n", op(rmd1, rmd2));
            cout << endl;
        }
    }
    return 0;
}
2024/10/3 21:18
加载中...