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. 下载配置MySql,高速启动MySql批处理,MySQLclient软件SQL-Front的配置---ShinePans

    首先,下载 sql 绿色版,:  http://yunpan.cn/cgERHhTtV8XGh  提取码 85bc 然后解压就可以用, 安装文件夹下有bin文件夹,从里面的命令中启动服务 例如以下: ...

  2. 在Ubuntu上下载、编译和安装Android最新内核源代码(Linux Kernel)

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6564592 在前一篇文章提到,从源代码树下载下 ...

  3. HDOJ 4937 Lucky Number

    当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Numb ...

  4. 如何给你的Android 安装文件(APK)瘦身

    如何给你的Android 安装文件(APK)瘦身 本文翻译自:Putting Your APKs on Diet           原作者:Cyril Mottier Android的apk文件越来 ...

  5. storm启动流程

    email:chenguibin2004@126.com storm: 是一个分布式的实时流式计算框架,具有低延迟.高可用.分布式.可扩展.数据不丢失的特点, storm包含四个核心组件: Nimbu ...

  6. image即时上传

    function preview_upload(input, img_div_id){ var img_id = img_div_id.replace("itempic_previewDiv ...

  7. 提高jQuery执行效率

    1. 使用最新版本的jQuery jQuery的版本更新很快,你应该总是使用最新的版本.因为新版本会改进性能,还有很多新功能. 下面就来看看,不同版本的jQuery性能差异有多大.这里是三条最常见的j ...

  8. 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 ...

  9. Linux虚机centos6.5安装Vmware Tools步骤

    退出到windows,在虚拟机菜单栏中点击 虚拟机-> 安装 VMWARE TOOLS 子菜单 进入到Linux系统,选择系统工具-终端  命令 su root 或者 su 以root进入 挂在 ...

  10. 对arm指令集的疑惑,静态库运行,编译报错等问题

    转载自http://www.jianshu.com/p/4a70aa03a4ea?utm_campaign=hugo&utm_medium=reader_share&utm_conte ...