結果
問題 |
No.8056 量子コンピュータで素因数分解 Easy
|
ユーザー |
|
提出日時 | 2020-02-06 05:22:59 |
言語 | Java (openjdk 23) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,601 bytes |
コンパイル時間 | 4,868 ms |
コンパイル使用メモリ | 84,896 KB |
実行使用メモリ | 105,264 KB |
平均クエリ数 | 0.46 |
最終ジャッジ日時 | 2024-12-31 20:03:09 |
合計ジャッジ時間 | 78,474 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 TLE * 24 |
ソースコード
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)); } }