結果
| 問題 |
No.8056 量子コンピュータで素因数分解 Easy
|
| ユーザー |
|
| 提出日時 | 2020-02-05 11:35:52 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 460 ms / 2,000 ms |
| コード長 | 1,148 bytes |
| コンパイル時間 | 2,432 ms |
| コンパイル使用メモリ | 80,404 KB |
| 実行使用メモリ | 73,220 KB |
| 平均クエリ数 | 3.12 |
| 最終ジャッジ日時 | 2024-12-31 19:42:54 |
| 合計ジャッジ時間 | 11,850 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import java.util.*;
import java.io.*;
import java.math.*;
// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.
class Main
{
public static void main(String[] args)
{
new Main().run();
}
void run(){
Scanner sc=new Scanner(System.in);
BigInteger N=new BigInteger(sc.next());
for(int i=2;;++i){
if(!N.gcd(BigInteger.valueOf(i)).equals(BigInteger.ONE))continue;
System.out.println("? "+ i);
BigInteger ord=new BigInteger(sc.next());
if(ord.mod(BigInteger.TWO).equals(BigInteger.ZERO)) {
BigInteger b=BigInteger.valueOf(i).modPow(ord.divide(BigInteger.TWO), N);
b=b.add(BigInteger.ONE);
BigInteger p=N.gcd(b);
if(!p.equals(BigInteger.ONE)&&!p.equals(N)) {
System.out.println("! "+p+" "+N.divide(p));
return;
}
}
}
}
int ord(BigInteger a, BigInteger mod){
for(int i=1;;++i){
if(a.modPow(BigInteger.valueOf(i),mod).equals(BigInteger.ONE))return i;
}
}
void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}
// OpenJDK reference:
// http://openjdk.java.net/
// Java language references:
// http://docs.oracle.com/javase