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. 转:python webdriver API 之对话框处理

    页面上弹出的对话框是自动化测试经常会遇到的一个问题:很多情况下对话框是一个 iframe,如上一节中介绍的例子,处理起来稍微有点麻烦:但现在很多前端框架的对话框是 div 形式的,这就让我们的处理变得 ...

  2. struts请求基本类型参数接收

    01:导包,web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app version ...

  3. WPF中实现

    计算类的封装 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespa ...

  4. C语言 类型

    int 2个字节或4个字节 根据平台而定, -32,768 到 32,767 或 -2,147,483,648 到 2,147,483,647 unsigned int 2或4个字节    0到655 ...

  5. JS获取项目根目录

    function getRootPath(){ //获取当前网址,如: http://localhost:8088/test/test.jsp var curPath=window.document. ...

  6. 1. 星际争霸之php面向对象(一)

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  7. [php]表单和验证

    <?php /* 表单的作用: 通过表单 发布和收集 信息. 对html表单进行编码 只是有效接受用户输入的必要操作的(一部分), 必须由[服务器端]组件来处理 一 标头函数(header()) ...

  8. sql创建删除修改表的基本操作

    1 建立表格 在建立好数据库以后,就可以根据储存资料的需求,使用SQL叙述建立所有需要的表格(table).建立表格的设定非常多,以建立"world.city"表格来说,它的叙述会 ...

  9. PHP开发框架Laravel优点,Laravel5.3中文文档

    PHP开发框架Laravel优点 Laravel的设计思想是很先进的,非常适合应用各种开发模式TDD, DDD和BDD,作为一个框架,它为你准备好了一切,composer是个php的未来,没有comp ...

  10. linux下的module_param()解释【转】

    转自:http://blog.csdn.net/wavemcu/article/details/7762133 版权声明:本文为博主原创文章,未经博主允许不得转载. ***************** ...