# HDU - 4002 Find the maximum （Java大数打表）

HDU - 4002
 Time Limit: 1000MS Memory Limit: 65768KB 64bit IO Format: %I64d & %I64u

Description

Euler's Totient function, φ (n) [sometimes called the phi function], is used to determine the number of numbers less than n which are relatively prime to n . For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, φ(9)=6.
HG is the master of X Y. One day HG wants to teachers XY something about Euler's Totient function by a mathematic game. That is HG gives a positive integer N and XY tells his master the value of 2<=n<=N for which φ(n) is a maximum. Soon HG finds that this seems a little easy for XY who is a primer of Lupus, because XY gives the right answer very fast by a small program. So HG makes some changes. For this time XY will tells him the value of 2<=n<=N for which n/φ(n) is a maximum. This time XY meets some difficult because he has no enough knowledge to solve this problem. Now he needs your help.

Input

There are T test cases (1<=T<=50000). For each test case, standard input contains a line with 2 ≤ n ≤ 10^100.

Output

For each test case there should be single line of output answering the question posed above.

Sample Input

2 10 100

Sample Output

6 30

Hint

If the maximum is achieved more than once, we might pick the smallest such n.


Source

The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
//题意： 规定fai（n）的值为比n小且与n互质的数的个数

//思路：

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
static int vis[] = new int[1010];
static int p[] = new int[1010];
static BigInteger a[] = new BigInteger[110];
static void getp()
{
for(int i = 0; i < 1010; i++)
vis[i] = 0;
vis[1] = 1;
for(int i = 2; i <= 1000; i++)
{
if(vis[i] == 0)
for(int j = i * i; j <= 1000; j += i)
{
vis[j] = 1;
}
}
int tp = 0;
for(int i = 1; i <= 1000; i++)
{
if(vis[i] == 0)
p[tp++] = i;
}
}
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
getp();
a[0]=BigInteger.valueOf(1);
for(int i=1;i<=100;i++)
{
a[i] = a[i-1].multiply(BigInteger.valueOf(p[i-1]));
}
int t = cin.nextInt();
while(t-- > 0)
{
BigInteger x;
x = cin.nextBigInteger();
if(x.compareTo(BigInteger.valueOf(6)) < 0){
System.out.println("2");
continue;
}
for(int i=0;i<=100;i++)
{
if(a[i].equals(x)){
System.out.println(a[i]);
break;
}
else if(a[i].compareTo(x) > 0)
{
System.out.println(a[i-1]);
break;
}
}
}
}
}


#### hdu 4002 - Find the maximum

2014-09-18 17:13:41

#### hdu 4002 数论 打表找规律 Find the maximum

2012-08-27 16:52:14

#### HDU：2612 Find a way（双BFS+打表）

2016-07-30 00:48:15

#### B - Find the maximum HDU - 4002

2017-11-14 15:08:18

#### HDU 4002 Find the maximum(欧拉函数)

2011-09-03 23:05:43

#### hdoj Find the maximum 4002 （欧拉函数&&大数打表）

2015-12-11 09:52:50

#### HDU高精度总结（java大数类）

2015-08-17 11:15:17

#### HDU 4002 Find the maximum（C++大整数实现+打表）

2016-09-21 16:44:29

#### HDU-OJ-2553 N皇后问题(打表/位运算)

2014-04-13 00:38:27

#### 组合数打表（小模板）

2016-08-10 20:58:45