Acdream 1670数一のアイドル2(ACdreamer javaスペシャル)
【タイトルリンク】:click here~~
【問題の大意】:
Problem Description
もう一つのアイドルはオラ!同様に、オラ様には多くのオラの定理と有名なオラ関数があります.
オーラ関数phi(x)は、xの正の整数におけるxとの相互質の数を超えない個数を表す.nを超えない整数の中でphi(x)/xを最小にするxはいくらですか?
Input
複数のグループのデータ、各グループのデータは1つの整数nだけあって、nは100ビットを超えません
Output
整数xを出力し、phi(x)/xが等しいxが複数ある場合は、最小のxを出力します.
Sample Input
Sample Output
【考え方】この問題はHDU 4002と同様であり、前処理素因子の積である.
コード:
【問題の大意】:
Problem Description
もう一つのアイドルはオラ!同様に、オラ様には多くのオラの定理と有名なオラ関数があります.
オーラ関数phi(x)は、xの正の整数におけるxとの相互質の数を超えない個数を表す.nを超えない整数の中でphi(x)/xを最小にするxはいくらですか?
Input
複数のグループのデータ、各グループのデータは1つの整数nだけあって、nは100ビットを超えません
Output
整数xを出力し、phi(x)/xが等しいxが複数ある場合は、最小のxを出力します.
Sample Input
1
2
3
Sample Output
1
2
2
【考え方】この問題はHDU 4002と同様であり、前処理素因子の積である.
コード:
/*
* this code is made by herongwei
* Problem: 1670
* Verdict: Accepted
* Submission Date: 2015-09-22 22:47:57
* Time: 172MS
* Memory: 26376KB
*/
//package ac0901;
import java.io.*;
import java.util.*;
import java.math.BigInteger;// BigInteger
import java.lang.*;
public class Main
{
public static void main(String args[])
{
Scanner cin = new Scanner(new BufferedInputStream(System.in));
final int N=100005;
boolean[] ok=new boolean[N];
int [] prime= new int [N];
int cnt=0;
BigInteger [] fac= new BigInteger [65];
for(int i=0; i<N; ++i) ok[i]=false;
for(int i=2; i<N; ++i)
{
if(!ok[i]) prime[cnt++]=i;
for(int j=0; j<cnt&&i*prime[j]<N; ++j)
{
ok[i*prime[j]]= true;
if(i%prime[j]==0) break;
}
}
fac[0]=BigInteger.ONE;
for(int i=1; i<=60; ++i)
{
fac[i]=fac[i-1].multiply(BigInteger.valueOf(prime[i-1]));
}
BigInteger n;
//int t;
//t=cin.nextInt();
//while(t-->0)
while(cin.hasNext())
{
n=cin.nextBigInteger();
for(int i=1; i<=60; ++i)
{
if(fac[i].compareTo(n)>0)
{
System.out.println(fac[i-1]);
break;
}
}
}
}
}