結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 303 ms
73,140 KB
testcase_03 AC 303 ms
74,132 KB
testcase_04 AC 219 ms
73,384 KB
testcase_05 AC 218 ms
73,448 KB
testcase_06 AC 224 ms
71,228 KB
testcase_07 AC 234 ms
73,056 KB
testcase_08 AC 230 ms
72,692 KB
testcase_09 AC 231 ms
72,956 KB
testcase_10 AC 239 ms
73,316 KB
testcase_11 WA -
testcase_12 AC 279 ms
72,948 KB
testcase_13 AC 233 ms
73,884 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 251 ms
73,564 KB
testcase_17 AC 247 ms
71,344 KB
testcase_18 AC 250 ms
72,872 KB
testcase_19 WA -
testcase_20 AC 292 ms
73,936 KB
testcase_21 AC 246 ms
73,600 KB
testcase_22 WA -
testcase_23 AC 261 ms
73,600 KB
testcase_24 AC 271 ms
74,720 KB
testcase_25 AC 207 ms
73,360 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)))
					end(R.subtract(ONE));
				break;
			}
		}
	}
}
0