結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2024-01-05 23:59:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 5,669 ms
コンパイル使用メモリ 382,392 KB
実行使用メモリ 24,012 KB
平均クエリ数 1.96
最終ジャッジ日時 2024-01-05 23:59:24
合計ジャッジ時間 9,554 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
24,012 KB
testcase_01 AC 58 ms
24,012 KB
testcase_02 AC 101 ms
24,000 KB
testcase_03 AC 104 ms
24,012 KB
testcase_04 AC 55 ms
24,000 KB
testcase_05 AC 57 ms
24,000 KB
testcase_06 AC 58 ms
24,000 KB
testcase_07 AC 56 ms
24,000 KB
testcase_08 AC 60 ms
24,000 KB
testcase_09 AC 59 ms
24,000 KB
testcase_10 AC 61 ms
24,000 KB
testcase_11 AC 88 ms
24,000 KB
testcase_12 AC 71 ms
24,000 KB
testcase_13 AC 59 ms
24,000 KB
testcase_14 AC 81 ms
24,000 KB
testcase_15 AC 82 ms
24,000 KB
testcase_16 AC 68 ms
24,000 KB
testcase_17 AC 72 ms
24,000 KB
testcase_18 AC 73 ms
24,000 KB
testcase_19 AC 89 ms
24,000 KB
testcase_20 AC 95 ms
24,000 KB
testcase_21 AC 70 ms
24,000 KB
testcase_22 AC 67 ms
24,000 KB
testcase_23 AC 80 ms
24,000 KB
testcase_24 AC 74 ms
24,000 KB
testcase_25 AC 52 ms
24,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    check(n, (bigint)3);
    for(int a = 2;; a += 1) {
    	check(n, (bigint)a);
	    std::cout << "? " << a << '\n';
	    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);
		}
    }
}
0