結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 229 ms
71,652 KB
testcase_02 AC 309 ms
71,740 KB
testcase_03 AC 303 ms
73,208 KB
testcase_04 AC 224 ms
72,884 KB
testcase_05 AC 207 ms
73,076 KB
testcase_06 AC 234 ms
73,208 KB
testcase_07 AC 225 ms
73,452 KB
testcase_08 AC 232 ms
73,388 KB
testcase_09 AC 231 ms
72,700 KB
testcase_10 AC 238 ms
72,948 KB
testcase_11 AC 288 ms
74,772 KB
testcase_12 AC 268 ms
72,868 KB
testcase_13 AC 240 ms
72,912 KB
testcase_14 AC 435 ms
74,052 KB
testcase_15 AC 421 ms
76,664 KB
testcase_16 AC 243 ms
73,792 KB
testcase_17 AC 248 ms
73,180 KB
testcase_18 AC 271 ms
73,808 KB
testcase_19 AC 427 ms
74,280 KB
testcase_20 AC 290 ms
74,704 KB
testcase_21 AC 244 ms
73,216 KB
testcase_22 AC 284 ms
74,828 KB
testcase_23 AC 255 ms
75,168 KB
testcase_24 AC 274 ms
72,532 KB
testcase_25 AC 208 ms
72,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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(BigInteger.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(long i=2;true;++i){
			System.out.println("? "+i);

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