結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 221 ms
72,916 KB
testcase_02 AC 312 ms
72,852 KB
testcase_03 AC 302 ms
74,212 KB
testcase_04 AC 218 ms
72,772 KB
testcase_05 AC 219 ms
73,416 KB
testcase_06 AC 225 ms
73,412 KB
testcase_07 AC 223 ms
72,312 KB
testcase_08 AC 224 ms
72,932 KB
testcase_09 AC 229 ms
73,224 KB
testcase_10 AC 225 ms
73,080 KB
testcase_11 AC 271 ms
74,996 KB
testcase_12 AC 274 ms
72,540 KB
testcase_13 AC 230 ms
74,228 KB
testcase_14 AC 405 ms
73,300 KB
testcase_15 AC 392 ms
74,108 KB
testcase_16 AC 242 ms
73,320 KB
testcase_17 AC 247 ms
72,896 KB
testcase_18 AC 264 ms
73,992 KB
testcase_19 AC 418 ms
73,924 KB
testcase_20 AC 285 ms
73,772 KB
testcase_21 AC 243 ms
72,480 KB
testcase_22 AC 277 ms
74,672 KB
testcase_23 AC 255 ms
75,136 KB
testcase_24 AC 273 ms
72,700 KB
testcase_25 AC 204 ms
72,904 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){
		var gcd=r.gcd(n);
		if(!gcd.equals(n)&&!gcd.equals(ONE)){
			System.out.println("! "+gcd+" "+n.divide(gcd));
			return true;
		}
		return false;
	}

	static BigInteger n;

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

		for(int i=2;true;++i){
			System.out.println("? "+i);
			if(end(BigInteger.valueOf(i)))
				return;
			var r=s.nextBigInteger().divideAndRemainder(TWO);
			if(r[1].equals(ZERO)){
				var R=valueOf(i).modPow(r[0],n);
				if(end(R.add(ONE)))
					return;
				if(end(R.subtract(ONE)))
					return;
			}
		}
	}
}
0