結果
問題 |
No.8056 量子コンピュータで素因数分解 Easy
|
ユーザー |
|
提出日時 | 2020-02-06 05:25:55 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 378 ms / 2,000 ms |
コード長 | 1,602 bytes |
コンパイル時間 | 4,397 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 73,192 KB |
平均クエリ数 | 2.35 |
最終ジャッジ日時 | 2024-12-31 20:00:45 |
合計ジャッジ時間 | 13,512 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
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(1); 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 = X.modPow(T.shiftRight(1), N).add(BigInteger.ONE); BigInteger M1 = X.modPow(T.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)); } }