Find the maximum

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

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
题解:先算出来前100个数;找规律;由于数太大,用java;
代码:
import java.math.BigInteger;
import java.util.Scanner; public class Main {
static int vis[] = new int[];
static int p[] = new int[];
static BigInteger a[] = new BigInteger[];
static void getp()
{
for(int i = ; i < ; i++)
vis[i] = ;
vis[] = ;
for(int i = ; i <= ; i++)
{
if(vis[i] == )
for(int j = i * i; j <= ; j += i)
{
vis[j] = ;
}
}
int tp = ;
for(int i = ; i <= ; i++)
{
if(vis[i] == )
p[tp++] = i;
}
}
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
getp();
a[]=BigInteger.valueOf();
for(int i=;i<=;i++)
{
a[i] = a[i-].multiply(BigInteger.valueOf(p[i-]));
}
int t = cin.nextInt();
while(t-- > )
{
BigInteger x;
x = cin.nextBigInteger();
// for(int i = 0; i <= 10; i++){
// System.out.println(a[i]);
// }
if(x.compareTo(BigInteger.valueOf()) < ){
System.out.println("");
continue;
}
for(int i=;i<=;i++)
{
if(a[i].equals(x)){
System.out.println(a[i]);
break;
}
else if(a[i].compareTo(x) > )
{
System.out.println(a[i-]);
break;
}
}
}
}
}

Find the maximum(规律,大数)的更多相关文章

  1. hdu 5351 规律+大数

    题目大意:定义了一种fib字符串,问第n个fib串的前m个字母前后相等串的最大长度,大约就是这样的 其实主要读完题意的时候并没有思路,但是列几个fib字符串就会发现,除了fib1以外,所有串的前面都是 ...

  2. UVA 10254 - The Priest Mathematician (dp | 汉诺塔 | 找规律 | 大数)

    本文出自   http://blog.csdn.net/shuangde800 题目点击打开链接 题意: 汉诺塔游戏请看 百度百科 正常的汉诺塔游戏是只有3个柱子,并且如果有n个圆盘,至少需要2^n- ...

  3. HDOJ-1041 Computer Transformation(找规律+大数运算)

    http://acm.hdu.edu.cn/showproblem.php?pid=1041 有一个初始只有一个1的串 每次都按①0 -> 10;②1 -> 01;这两条规则进行替换 形如 ...

  4. Resistors in Parallel(找规律+大数)

    题意:https://codeforces.com/group/ikIh7rsWAl/contest/254825/problem/E 给你一个n,计算n / Sigma(1~n)的d(是n的只出现一 ...

  5. 2017ACM/ICPC亚洲区沈阳站-重现赛

    HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...

  6. 2018 ACM-ICPC 亚洲区域赛北京现场赛 I题 Palindromes

    做法:打表找规律 大数是过不了这个题的(但可以用来打表) 先找k的前缀,前缀对应边缘数字是哪个 如果第0位是2-9 对应奇数长度的1-8 第0位为1时,第1位为0时对应奇数长度的9,为1-9时对应偶数 ...

  7. HDU6415 Rikka with Nash Equilibrium

    HDU6415 Rikka with Nash Equilibrium 找规律 + 大数 由于规律会被取模破坏,所以用了java 找出规律的思路是: 对于一个n*m的矩阵构造,我先考虑n*1的构造,很 ...

  8. Codeforces Round #260 (Div. 2) A B C 水 找规律(大数对小数取模) dp

    A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. hdu_1041(Computer Transformation) 大数加法模板+找规律

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

随机推荐

  1. oracle日期计算

    查询某月有多少天.代码例如以下: select to_number(add_months( trunc(to_date('2014-11-4 11:13:53','yyyy-mm-dd hh24:mi ...

  2. 寒哥细谈之AutoLayout全解

    文/南栀倾寒(简书作者)原文链接:http://www.jianshu.com/p/683fbcbfb705著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 看到群中好多朋友还停留在Fr ...

  3. c#转码解码

    ///反转码                          mdata[k].MNAME = unescape(mdata[k].MNAME);程家楠 13:51:00 Microsoft.JSc ...

  4. 事件监听:诀别Android繁琐的事件注册机制——view.setOnXXXXListener

    本版本为1.0,支持较少,使用不够方便.相关封装逻辑结构已升级至2.0,详情可参见:更完善的安卓事件监听实现 先简单扯两句这几天学习下来对java事件监听机制的一点感触.客观地讲,java的事件监听机 ...

  5. 《第一行代码》学习笔记29-内容提供器Content Provider(2)

    1.查询操作: if (cursor != null) { while (cusor.moveToNext()) { String column1 = cursor.getString(cursor. ...

  6. How to resolve the SQL error “cannot connect to WMI provider”

    当你试图打开SQL Server Configuation Manager时发现如下错误: “cannot connect to WMI provider. You do not have permi ...

  7. iOS图片拉伸技巧—— resizableImageWithCapInsets

    http://blog.csdn.net/chaoyuan899/article/details/19811889

  8. IOS网络开发实战(一)

      1 局域网群聊软件 1.1 问题 UDP协议将独立的数据包从一台计算机传输到另外一台计算机,但是并不保证接受方能够接收到该数据包,也不保证接收方所接收到的数据和发送方所发送的数据在内容和顺序上是完 ...

  9. nginx配置时的一些问题

    在配置nginx的时候出现的一些问题,在此记录: 1.如何打开nginx服务: 方法1:打开解压的下载文件,双击打开nginx.exe即可(出现闪退,我以为是出问题了,其实是服务已经启动了) 方法2: ...

  10. VMware 虚拟机使用RedHat,出现 connect: Network is unreachable解決方法

    http://www.linuxidc.com/Linux/2015-02/113119.htm http://www.osyunwei.com/archives/7829.html