結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2024-01-05 23:39:52
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 958 bytes
コンパイル時間 7,361 ms
コンパイル使用メモリ 398,572 KB
実行使用メモリ 40,928 KB
平均クエリ数 0.04
最終ジャッジ日時 2024-01-05 23:40:10
合計ジャッジ時間 12,665 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
24,012 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert> // assert
#include <cstdlib> // exit
#include <iostream> // cin, cout, ios
#include <utility> // swap
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/miller_rabin.hpp>
#include <boost/random/mersenne_twister.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() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
	boost::random::mt19937 gen;
	bigint n, r;
    std::cin >> n;
    check(n, (bigint)3);
    for(bigint a = (bigint)2; a < n; a += (bigint)1) {
    	check(n, a);
	    std::cout << "? " << a << '\n';
	    std::cin >> r;
		if((r & (bigint)1) == (bigint)0) {
			r >>= 1;
		}
		for(bigint b = (bigint)0; b < (bigint)99; b += (bigint)1) {
			check(n, mp::powm(a + b, r, n) - (bigint)1);
		}
    }
}
0