HDU 4002 find the maximum (Euler's function)

Source: Internet
Author: User
Find the maximum

Time Limit: 2000/1000 MS (Java/others) memory limit: 65768/65768 K (Java/Others)
Total submission (s): 1459 accepted submission (s): 632


Problem descriptioneuler's totient function, Phi (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, Phi (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 PHI (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/PHI (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.


Inputthere are t test cases (1 <= T <= 50000). For each test case, standard input contains a line with 2 ≤ n ≤ 10 ^ 100.


Outputfor each test case there shoshould be single line of output answering the question posed above.


Sample Input

 
210100


Sample output

 
630HintIf the maximum is achieved more than once, we might pick the smallest such n. 
Question: Find the maximum value of N/PHI (n) not greater than N. First, you must know that Phi (n) indicates the number of positive integers that do not exceed n and are mutually compatible with N.
Solution:Phi (x) = x (1-1/P1) (1-1/P2) (1-1/P3) (1-1/P4 )..... (1-1/PN)
P1 to PN is the prime factor of X, and N/PHI (n) indicates 1/(1-1/P1) (1-1/P2) (1-1/P3) (1-1/P4 )..... (1-1/PN), it is expected that when the prime factor is the most, the denominator is the smallest and the score is the largest. For details, seeCode.
Address: Find the maximum
AC code:
Import Java. util. *; import Java. io. *; import Java. math. *; public class main // qixifestival {public static void main (string ARGs []) {int mark [], I, j; // mark is 1, it indicates prim mark = new int [502]; for (I = 0; I <= 500; I ++) MARK [I] = 1; Mark [0] = 0; mark [1] = 0; for (I = 2; I <= 25; I ++) // filter prime numbers {If (MARK [I] = 1) {for (j = I * I; j <500; j + = I) MARK [J] = 0 ;}} biginteger prim []; // Save the prime number int T = 0; prim = new biginteger [102]; for (I = 2; I <= 500; I ++) if (Mark [I] = 1) prim [++ T] = biginteger. valueof (I); // system. out. println (t); biginteger res []; // stores the prime product, that is, the result res = new biginteger [80]; Res [1] = biginteger. valueof (2); for (I = 2; I <56; I ++) RES [I] = res [I-1]. multiply (prim [I]);/* string S = res [55]. tostring (); int Len = S. length (); system. out. println (LEN); * // output 104 description 55 can be loaded with 100 bits (system. in); int N; n = cin. nextint (); While (n! = 0) {n --; biginteger cur; cur = cin. nextbiginteger (); for (I = 55; I> = 1; I --) {If (RES [I]. compareto (cur) <= 0) {system. out. println (RES [I]); break ;}}}// 1406 Ms 4144 K

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.