結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2022-09-11 20:21:20
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 5,380 KB
実行使用メモリ 62,288 KB
平均クエリ数 3.04
最終ジャッジ日時 2023-08-30 06:59:03
合計ジャッジ時間 6,308 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
59,496 KB
testcase_01 AC 103 ms
59,364 KB
testcase_02 AC 147 ms
59,752 KB
testcase_03 AC 147 ms
60,348 KB
testcase_04 AC 97 ms
59,132 KB
testcase_05 AC 95 ms
59,248 KB
testcase_06 AC 101 ms
59,436 KB
testcase_07 AC 95 ms
58,912 KB
testcase_08 AC 100 ms
58,880 KB
testcase_09 AC 99 ms
59,492 KB
testcase_10 AC 98 ms
58,992 KB
testcase_11 AC 122 ms
60,512 KB
testcase_12 AC 145 ms
60,348 KB
testcase_13 AC 100 ms
59,624 KB
testcase_14 AC 207 ms
60,924 KB
testcase_15 AC 218 ms
62,288 KB
testcase_16 AC 109 ms
59,756 KB
testcase_17 AC 111 ms
59,256 KB
testcase_18 AC 116 ms
59,636 KB
testcase_19 AC 210 ms
60,616 KB
testcase_20 AC 135 ms
59,356 KB
testcase_21 AC 110 ms
59,496 KB
testcase_22 AC 121 ms
60,032 KB
testcase_23 AC 123 ms
59,268 KB
testcase_24 AC 117 ms
59,284 KB
testcase_25 AC 91 ms
59,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const modpow = (a, b, n) => {
    while((b & 1n) == 0n) { b >>= 1n; a = a * a % n; }
    let r = a;
    while(true) {
        b >>= 1n;
        if(b == 0n) { return r; }
        a = a * a % n;
        if((b & 1n) != 0) { r = r * a % n; }
    }
};
const gcd = (a, b) => {
    while(b != 0n) { let t = a % b; a = b; b = t; }
    return a;
};

const hrStart = process.hrtime();
let n = null;
let a = 2n;
process.stdin.setEncoding("utf8");
const reader = require("readline").createInterface({input: process.stdin});
const checkgcd = (x) => {
    let g = gcd(n, x);
    if (g > 1n && g < n) {
        console.log(`! ${g} ${n/g}`);
        const hrEnd = process.hrtime(hrStart);
        console.error(`${hrEnd[0]*1e3+hrEnd[1]/1e6}ms`);
        process.exit();
    }
}
reader.on("line", (l) => {
    if (n === null) {
        n = BigInt(l);
    } else {
        let r = BigInt(l);
        let t = modpow(a, r >> 1n, n);
        checkgcd(t - 1n);
        checkgcd(t + 1n);
        a += 1n;
        checkgcd(a);
    }
    console.log(`? ${a}`);
});
0