結果
問題 |
No.8056 量子コンピュータで素因数分解 Easy
|
ユーザー |
|
提出日時 | 2020-02-05 22:21:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 891 bytes |
コンパイル時間 | 1,820 ms |
コンパイル使用メモリ | 170,384 KB |
実行使用メモリ | 821,976 KB |
平均クエリ数 | 0.08 |
最終ジャッジ日時 | 2024-12-31 19:53:20 |
合計ジャッジ時間 | 39,325 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 TLE * 1 MLE * 24 |
ソースコード
#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; } 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) continue; cout << "? " << p << endl; ull r; 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; }