結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
24,012 KB
testcase_01 AC 61 ms
24,012 KB
testcase_02 AC 107 ms
24,000 KB
testcase_03 AC 104 ms
24,012 KB
testcase_04 AC 57 ms
24,000 KB
testcase_05 AC 56 ms
24,000 KB
testcase_06 AC 59 ms
24,000 KB
testcase_07 AC 57 ms
24,000 KB
testcase_08 AC 60 ms
24,000 KB
testcase_09 AC 60 ms
24,000 KB
testcase_10 AC 61 ms
24,000 KB
testcase_11 AC 62 ms
24,000 KB
testcase_12 AC 70 ms
24,000 KB
testcase_13 AC 61 ms
24,000 KB
testcase_14 AC 81 ms
24,000 KB
testcase_15 AC 84 ms
24,000 KB
testcase_16 AC 69 ms
24,000 KB
testcase_17 AC 73 ms
24,000 KB
testcase_18 AC 74 ms
24,000 KB
testcase_19 AC 91 ms
24,000 KB
testcase_20 AC 97 ms
24,000 KB
testcase_21 AC 70 ms
24,000 KB
testcase_22 AC 68 ms
24,000 KB
testcase_23 AC 81 ms
24,000 KB
testcase_24 AC 76 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;
    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);
	    }
	    bigint r;
	    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