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. 无向连通图求割边+缩点+LCA

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7082   Accepted: 2555 Descripti ...

  2. po line received is canceled(恢复PO被取消的余量)

    1張PO已部分收貨,後來由于某種原因,將部分收貨的PO明行取消,現在要對已收料的這一部分進行退貨處理,要怎麼做才好呢? [@more@]DATA COLLECTED===============COL ...

  3. 夺命雷公狗---DEDECMS----1dedecms的安装过程

    我们这次要玩的dedecms(cms也就是内容管理系统),电商网.或者政府网..小说网.新闻网之类的都是基于可以用cms来实现的. 现在在市场上主流的cms系统有dedecms(织梦),帝国cms,p ...

  4. Deep Learning 深度学习 学习教程网站集锦

    http://blog.sciencenet.cn/blog-517721-852551.html 学习笔记:深度学习是机器学习的突破 2006-2007年,加拿大多伦多大学教授.机器学习领域的泰斗G ...

  5. 关于VS 中 HttpHandler 的设置 500.23

    前一段时间在讲 HttpHandler 的过程中遇到一些问题,在此分享一下. 使用VS2012 添加HttpHandler后,在web.config配置的节点如下: <?xml version= ...

  6. java类的访问权限

    1.解析 Java有四种访问权限, 其中三种有访问权限修饰符,分别为private,public和protected,还有一种不带任何修饰符. private: Java语言中对访问权限限制的最窄的修 ...

  7. UIPage

    分页控件是一种用来取代导航栏的可见指示器,方便手势直接翻页,最典型的应用便是iPhone的主屏幕,当图标过多会自动增加页面,在屏幕底部你会看到原点,用来只是当前页面,并且会随着翻页自动更新. 一.创建 ...

  8. sql字段类型介绍

    1 表格与储存引擎 表格(table)是数据库中用来储存纪录的基本单位,在建立一个新的数据库以后,你必须为这个数据库建立一些储存资料的表格: 每一个数据库都会使用一个资料夹,这些数据库资料夹用来储存所 ...

  9. JSP在项目中的路径问题

    一.JSP中获得当前应用的相对路径和绝对路径  根目录所对应的绝对路径 : request.getRequestURI() 文件的绝对路径 : application.getRealPath(requ ...

  10. Linux和Windows远程桌面互连

    1.Ubuntu 连 windows    W.1 Windows设置允许远程桌面连接    U.1 Ubuntu设置 apt-get install rdesktop    U.2 Ubuntu连接 ...