結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー fine
提出日時 2020-02-05 22:26:44
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 1,083 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,604 ms
コンパイル使用メモリ 182,616 KB
実行使用メモリ 1,316,632 KB
平均クエリ数 0.08
最終ジャッジ日時 2026-06-05 08:44:24
合計ジャッジ時間 5,770 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 MLE * 2 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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