`
lilisalo
  • 浏览: 1102275 次
文章分类
社区版块
存档分类
最新评论

HDU/HDOJ 4002 2011大连赛区网络赛 数论

 
阅读更多

Find the maximum

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


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
这个题目其实是个水题的。
但是之前他们出题的把样例搞错了。于是一直WA。。
我说说我的做法吧。
这个题的目的是找n/phi(n)的最大值
这里可以对这个式子变下形
n/phi(n)=[p1^a1*p2^a2*...pn^an]/[phi(p1^a1)*phi(p2^a2)*...*phi(pn^an)]
由于phi(p^k),当p为质数的时候=p^k-p^(k-1)
式子进一步化简变为:
(p1/(p1-1))*(p2/(p2-1))*...*(pn/(pn-1))
那么从这个式子就可以看出来,n/phi(n)的大小只与n的质因子有关
其实这里就得到了一个结论,要让这个式子最大,那么n就必然是一些质数的积
即是说:n=2*3*5*7*11*。。。。
直到最大的那个不能超过输入数据N的那儿
我的代码:

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics