Find the maximum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1561    Accepted Submission(s): 680

Problem 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
 import java.io.*;
import java.awt.*;
import java.math.BigInteger;
import java.util.Scanner; public class Main { static int prime[] = new int [];
static int len = ;
static BigInteger dp[] = new BigInteger[];
public static void main(String[] args) {
fun();
int T=;
Scanner cin = new Scanner(System.in);
T=cin.nextInt();
while(T>)
{
BigInteger n = cin.nextBigInteger();
int x=;
for(int i=;i<=len;i++)
{
if(n.compareTo(dp[i])<)
{
x=i-;
break;
}
}
System.out.println(dp[x]);
T--;
}
}
static void fun(){
boolean s[] = new boolean[];
for(int i=;i<s.length;i++){
s[i]=false;
}
for(int i=;i<dp.length;i++){
dp[i]=BigInteger.ZERO;
}
for(int i=;i<;i++)
{
if(s[i]==true) continue;
prime[++len]=i;
for(int j=i*;j<;j=j+i)
s[j]=true;
}
dp[] = BigInteger.ONE;
for(int i=;i<=len;i++)
{
dp[i] = dp[i-].multiply(BigInteger.valueOf(prime[i]));
}
}
}

hdu 4002 Find the maximum的更多相关文章

  1. HDU 4002 Find the maximum(欧拉函数)

    题目链接 猜了一个结论,题面跟欧拉函数有关系. import java.util.*; import java.math.*; import java.text.*; import java.io.* ...

  2. hdu 1839 Delay Constrained Maximum Capacity Path 二分/最短路

    Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu. ...

  3. hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)

    Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65 ...

  4. hdu 4002 欧拉函数 2011大连赛区网络赛B

    题意:求1-n内最大的x/phi(x) 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是 ...

  5. HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online

    意甲冠军: 特定n小点的树权. 以下n每一行给出了正确的一点点来表达一个销售点每只鸡价格的格 以下n-1行给出了树的侧 以下Q操作 Q行 u, v, val 从u走v,程中能够买一个鸡腿,然后到后面卖 ...

  6. hdu 1839 Delay Constrained Maximum Capacity Path

    最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio&g ...

  7. Hdu 5052 Yaoge’s maximum profit(树链剖分)

    题目大意: 给出一棵树.每一个点有商店.每一个商店都有一个价格,Yaoge每次从x走到y都能够在一个倒卖商品,从中得取利益.当然,买一顶要在卖之前.可是没次走过一条路,这条路上的全部商品都会添加一个v ...

  8. HDU 6047 Maximum Sequence(线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  9. HDU 2459 Maximum repetition substring

    题目:Maximum repetition substring 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2459 题意:给你一个字符串,求连续重复出现 ...

随机推荐

  1. 创建一个web Test Plan

    1.添加ThreadGroup (1).线程组界面解析: 线程数:虚拟用户的个数 Ramp-up Period:开启每个用户的延迟时间,如果有5个虚拟用户,Ramp-up Period值是5,Jmet ...

  2. collection和collections区别

    collection和collections区别 collection-->是集合类的上级接口,继承他的接口主要有set,list collections-->是针对集合类的一个帮助类,提 ...

  3. eclipse的debug模式启动缓慢

      这个问题可能是由于eclipse和服务器的交互而产生的,在以debug模式启动服务器时,发生了读取文件错误,eclipse自动设置了断点,导致服务器不能正常启动. 解决方法如下:以debug模式启 ...

  4. nginx指定配制文件

    nginx启动: 未指定配制文件: ./nginx 指定配制文件: /usr/local/nginx/sbin/nginx -c /home/deploy/nginx-wz/conf/nginx.co ...

  5. ThinkPHP讲解(八)——显示、修改、添加、删除

    一.显示数据 <h1>主页面</h1> <table width="100%" border="1" cellpadding=&q ...

  6. powershell: 生成随机字符串

    ASCII范围内的 获取6个随机字符(字母和数字) 48到57是数字0-9,powershell的范围操作符是..,和Perl 5的一样, 所以 48..57就是指(48 49 50 51 52 53 ...

  7. 浅析Java的HashCode,以及equals

    1.JDK规定,equals相等的两个对象hashCode也必须相等,这两个方法都是从Object上面继承而来的,通过观察JDK源码可以发现Object的equals方法是对2个对象的地址(逻辑地址, ...

  8. Oracle主库归档丢失,备库日志有gap,在不重建备库的情况下,恢复备库

    本文主要描述Oracle备库日志与主库日志之间有gap,切主库这部分gap的归档日志已经删除或丢失,如何在不重建备库的情况下,恢复备库. 欢迎转载,请注明作者.出处. 作者:张正 blog:http: ...

  9. WKWebView与Js实战(OC版)

    前言 上一篇专门讲解了WKWebView相关的所有类.代理的所有API.那么本篇讲些什么呢?当然是实战了! 本篇文章教大家如何使用WKWebView去实现常用的一些API操作.当然,也会有如何与JS交 ...

  10. mysql表导入到oracle

    一.创建jack表,并导入一下数据 mysql),flwo )) engine=myisam; Query OK, rows affected (0.08 sec) mysql> load da ...