HDU - 4002 Find the maximum (Java大数打表)

原创 2016年06月01日 13:56:19
HDU - 4002
Time Limit: 1000MS   Memory Limit: 65768KB   64bit IO Format: %I64d & %I64u

Status

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互质的数的个数
给你一个数n,x是区间[1,n]中的任意一个数,找出最大的x/fai(x)的x。
//思路:
通过模拟找出规律:a[i]=a[i-1]*p[i-1](p[i]表示素数表),因为数很大所以用Java大数打表即可
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

题意:给出一个整数n,求一个数x,x在1到n之间,并且x/φ(x)最大(此中φ(x)为x的欧拉函数)。 思路: 由欧拉函数为积性函数,即:若是gcd(m , n) == 1,则有φ(m * n) ...
  • Julyana_Lin
  • Julyana_Lin
  • 2012年08月27日 16:52
  • 888

hdu 4002 - Find the maximum

题目:求不超过n的最大的x/φ(x),其中φ(x)是欧拉函数。 分析:数论,大整数。比赛时直接打表计算的。            实际上:φ(n)= n *(1 - 1/p1)*(1 - 1/p2...
  • mobius_strip
  • mobius_strip
  • 2014年09月18日 17:13
  • 729

HDU 4002 Find the maximum(欧拉函数)

题意:给出N , 求满足2 可知 fn=(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,在N的范围内时,满足fn的项...
  • jxy859
  • jxy859
  • 2011年09月03日 23:05
  • 594

B - Find the maximum HDU - 4002

Euler's Totient function, φ (n) [sometimes called the phi function], is used to determine the number...
  • Jack_zhuiyi
  • Jack_zhuiyi
  • 2017年11月14日 15:08
  • 38

hdoj Find the maximum 4002 (欧拉函数&&大数打表)

Find the maximum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others...
  • yanghui07216
  • yanghui07216
  • 2015年12月11日 09:52
  • 275

HDU 4002 Find the maximum(C++大整数实现+打表)

Problem Description Euler's Totient function, φ (n) [sometimes called the phi function], is used to...
  • mirror58229
  • mirror58229
  • 2016年09月21日 16:44
  • 380

HDU 4002 Find the maximum(JAVA 大数找规律 )

HDU 4002 Find the maximum(JAVA 大数找规律 )
  • u012860063
  • u012860063
  • 2015年09月24日 22:44
  • 425

HDU 4002 Find the maximum(数论-欧拉函数)

HDU 4002 Find the maximum(数论-欧拉函数) 题目大意: 给定一个n,问你1~n中,求一个数 x 使得 x/φ(x) 的值最大。 解题思路: 根据欧拉函数的公式,φ(x)...
  • a1061747415
  • a1061747415
  • 2014年08月03日 22:59
  • 753

大数组合数取模(逆元+打表)

将阶乘O(n)打表之后C(n,m)便可O(1)求出,除法取模用逆元解决 hdu5698瞬间移动#include using namespace std; const int maxn=200000;...
  • daniel_csdn
  • daniel_csdn
  • 2016年05月23日 11:04
  • 1108

Java大数求解ACM(HDU)

Java 大数求解ACM
  • LRita
  • LRita
  • 2016年05月16日 21:29
  • 1181
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:HDU - 4002 Find the maximum (Java大数打表)
举报原因:
原因补充:

(最多只允许输入30个字)