結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー uwiuwi
提出日時 2020-02-06 05:22:59
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,601 bytes
コンパイル時間 3,772 ms
コンパイル使用メモリ 87,796 KB
実行使用メモリ 100,952 KB
平均クエリ数 0.31
最終ジャッジ日時 2023-08-30 06:55:03
合計ジャッジ時間 7,759 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 207 ms
72,640 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package extra;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class P3056 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static BigInteger ord(BigInteger A)
	{
		out.println("? " + A);
		out.flush();
		return new BigInteger(in.next());
	}
	
	// https://qiita.com/satto_sann/items/373e974a451896d728bb
	static void solve()
	{
		BigInteger N = new BigInteger(in.next());
		int len = (N.bitLength()+7)/8;
		Random gen = new Random();
		while(true) {
			byte[] bs = new byte[len];
			gen.nextBytes(bs);
			BigInteger X = new BigInteger(bs).abs();
			if(X.compareTo(N) >= 0)continue;
			if(!X.gcd(N).equals(BigInteger.ONE))continue;
			BigInteger T = ord(X);
			
			BigInteger P1 = T.modPow(X.shiftRight(1), N).add(BigInteger.ONE);
			BigInteger M1 = T.modPow(X.shiftRight(1), N).subtract(BigInteger.ONE);
			P1 = P1.gcd(N);
			M1 = M1.gcd(N);
			if(
					!P1.equals(BigInteger.ONE) &&
					!M1.equals(BigInteger.ONE)) {
				out.println("! "  + P1 + " " + M1);
				out.flush();
				return;
			}
		}
	}
	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0