結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー fine
提出日時 2020-02-05 22:26:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,083 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 169,560 KB
実行使用メモリ 821,720 KB
平均クエリ数 0.15
最終ジャッジ日時 2024-12-31 19:52:36
合計ジャッジ時間 34,825 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 MLE * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ull = unsigned long long;

ull modpow(ull x, ull n, ull mod = -1) {
    ull res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ull calc(ull x, ull n) {
    ull cnt = 1;
    ull hoge = x % n;
    while (hoge != 1) {
        hoge = hoge * x % n;
        cnt++;
    }
    return cnt;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ull n;
    cin >> n;
    
    mt19937 mt(0);
    uniform_int_distribution<> rnd(1, n - 1);
    
    ull p = 0, q = 0;
    do {
        p = rnd(mt);
        if (p % 2 == 0 || __gcd(n, p) != 1) continue;
        cout << "? " << p << endl;
        ull r;// = calc(p, n);
        cin >> r;
        if (r % 2 == 1) continue;
        r >>= 1;
        ull hoge = modpow(p, r, n);
        if (hoge == 1 || hoge == n - 1) continue;
        p = __gcd(hoge + 1, n);
        q = __gcd(hoge + n - 1, n);
        break;
    } while (p * q != n);
    cout << "! " << p << " " << q << endl;
    return 0;
}
0