結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 202 ms
73,592 KB
testcase_01 AC 218 ms
71,752 KB
testcase_02 AC 299 ms
73,388 KB
testcase_03 AC 297 ms
74,080 KB
testcase_04 AC 216 ms
71,268 KB
testcase_05 AC 212 ms
73,068 KB
testcase_06 AC 221 ms
73,380 KB
testcase_07 AC 219 ms
72,576 KB
testcase_08 AC 224 ms
73,300 KB
testcase_09 AC 225 ms
73,240 KB
testcase_10 AC 223 ms
73,432 KB
testcase_11 AC 267 ms
74,280 KB
testcase_12 AC 268 ms
73,008 KB
testcase_13 AC 230 ms
72,848 KB
testcase_14 AC 405 ms
73,472 KB
testcase_15 AC 391 ms
73,688 KB
testcase_16 AC 241 ms
73,456 KB
testcase_17 AC 249 ms
72,688 KB
testcase_18 AC 248 ms
72,816 KB
testcase_19 AC 401 ms
74,792 KB
testcase_20 AC 279 ms
74,076 KB
testcase_21 AC 244 ms
73,508 KB
testcase_22 AC 279 ms
74,268 KB
testcase_23 AC 255 ms
73,656 KB
testcase_24 AC 267 ms
75,200 KB
testcase_25 AC 202 ms
73,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main{
	static boolean end(BigInteger r){
		var g=r.gcd(n);
		if(g.equals(n)||g.equals(ONE))
			return false;
		System.out.println("! "+g+" "+n.divide(g));
		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