結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー 37zigen
提出日時 2020-02-05 10:35:17
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 906 bytes
コンパイル時間 2,352 ms
コンパイル使用メモリ 77,168 KB
実行使用メモリ 72,312 KB
平均クエリ数 2.00
最終ジャッジ日時 2024-12-31 19:38:22
合計ジャッジ時間 9,042 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

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());
		System.out.println(N);
		for(int i=2;;++i){
			System.out.println("? i");
			int ord=sc.nextInt();
			if(ord%2==0) {
				BigInteger b=BigInteger.valueOf(i).modPow(BigInteger.valueOf(ord/2), N);
				b=b.add(BigInteger.ONE);
				BigInteger p=N.gcd(b);
				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;
		}
	}
}

// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase
0