結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー fal_rndfal_rnd
提出日時 2020-02-05 04:29:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 401 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 78,540 KB
実行使用メモリ 74,896 KB
平均クエリ数 3.04
最終ジャッジ日時 2023-08-30 06:48:47
合計ジャッジ時間 10,831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 205 ms
73,248 KB
testcase_01 AC 221 ms
73,280 KB
testcase_02 AC 295 ms
74,004 KB
testcase_03 AC 292 ms
73,408 KB
testcase_04 AC 218 ms
73,104 KB
testcase_05 AC 217 ms
72,980 KB
testcase_06 AC 218 ms
72,832 KB
testcase_07 AC 224 ms
73,456 KB
testcase_08 AC 224 ms
72,484 KB
testcase_09 AC 222 ms
72,500 KB
testcase_10 AC 225 ms
72,956 KB
testcase_11 AC 266 ms
74,896 KB
testcase_12 AC 268 ms
73,272 KB
testcase_13 AC 222 ms
73,512 KB
testcase_14 AC 394 ms
71,628 KB
testcase_15 AC 379 ms
73,660 KB
testcase_16 AC 245 ms
73,180 KB
testcase_17 AC 241 ms
73,500 KB
testcase_18 AC 248 ms
72,636 KB
testcase_19 AC 401 ms
73,124 KB
testcase_20 AC 282 ms
73,908 KB
testcase_21 AC 241 ms
72,868 KB
testcase_22 AC 267 ms
74,260 KB
testcase_23 AC 253 ms
71,264 KB
testcase_24 AC 264 ms
72,932 KB
testcase_25 AC 201 ms
72,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	static BigInteger n;

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

		for(int i=2;!end(valueOf(i));++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)))
					break;
				if(end(R.subtract(ONE)))
					break;
			}
		}
	}
}
0