結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー fal_rndfal_rnd
提出日時 2020-02-05 03:30:53
言語 Java21
(openjdk 21)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 722 bytes
コンパイル時間 2,940 ms
コンパイル使用メモリ 77,444 KB
実行使用メモリ 74,904 KB
平均クエリ数 3.04
最終ジャッジ日時 2023-08-30 06:47:54
合計ジャッジ時間 10,721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 223 ms
72,900 KB
testcase_02 AC 295 ms
73,808 KB
testcase_03 AC 293 ms
73,460 KB
testcase_04 AC 217 ms
73,244 KB
testcase_05 AC 217 ms
73,024 KB
testcase_06 AC 221 ms
73,128 KB
testcase_07 AC 214 ms
73,548 KB
testcase_08 AC 227 ms
74,236 KB
testcase_09 AC 226 ms
73,640 KB
testcase_10 AC 227 ms
73,040 KB
testcase_11 AC 272 ms
72,700 KB
testcase_12 AC 270 ms
73,836 KB
testcase_13 AC 224 ms
73,128 KB
testcase_14 AC 399 ms
73,464 KB
testcase_15 AC 377 ms
71,612 KB
testcase_16 AC 243 ms
73,468 KB
testcase_17 AC 246 ms
72,808 KB
testcase_18 AC 258 ms
74,108 KB
testcase_19 AC 413 ms
73,700 KB
testcase_20 AC 284 ms
74,492 KB
testcase_21 AC 243 ms
73,192 KB
testcase_22 AC 275 ms
74,904 KB
testcase_23 AC 263 ms
73,632 KB
testcase_24 AC 262 ms
74,448 KB
testcase_25 AC 201 ms
72,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.math.BigInteger.*;
import java.math.*;
import java.util.*;

// https://speakerdeck.com/gyudon/shorfalsearugorizumu?slide=7

class Main{
	static boolean end(BigInteger r,BigInteger n){
		var gcd=r.gcd(n);
		if(!gcd.equals(n)&&!gcd.equals(ONE)){
			System.out.println("! "+gcd+" "+n.divide(gcd));
			return true;
		}
		return false;
	}

	public static void main(String[] $){
		var s=new Scanner(System.in);
		var n=s.nextBigInteger();

		for(int i=2;true;++i){
			System.out.println("? "+i);

			var r=s.nextBigInteger().divideAndRemainder(TWO);
			if(r[1].equals(ZERO)){
				var R=valueOf(i).modPow(r[0],n);
				if(end(R.add(ONE),n))
					return;
				if(end(R.subtract(ONE),n))
					return;
			}
		}
	}
}
0