結果
問題 | No.8056 量子コンピュータで素因数分解 Easy |
ユーザー |
👑 |
提出日時 | 2024-01-06 00:20:26 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 738 bytes |
コンパイル時間 | 5,811 ms |
コンパイル使用メモリ | 372,616 KB |
実行使用メモリ | 25,220 KB |
平均クエリ数 | 2.04 |
最終ジャッジ日時 | 2024-09-27 19:12:44 |
合計ジャッジ時間 | 9,397 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <cstdlib> // exit #include <iostream> // cin, cout, ios #include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; using bigint = mp::cpp_int; void check(bigint& n, bigint v) { bigint g = mp::gcd(v, n); if(g > (bigint)2 && g < n) { std::cout << "! " << g << " " << n / g << '\n'; std::exit(0); } } int main() { bigint n, r; std::cin >> n; for(int a = 2;; a += 1) { if((a & 1) != 0) { check(n, (bigint)a); } std::cout << "? " << a << '\n'; if(a == 2) { check(n, (bigint)3); } std::cin >> r; if((r & (bigint)1) == (bigint)0) { r >>= 1; } for(int b = 0; b < 99; b += 1) { check(n, mp::powm(a + (bigint)b, r, n) - (bigint)1); } } }