Find the maximum (regular, large number)

Source: Internet
Author: User

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 Descriptioneuler ' s totient function,φ (n) [sometimes called the Phi function], is used to determine the number of Numbers less than n which is relatively prime to N. For example, as 1, 2, 4, 5, 7, and 8, is all less than nine and relatively primes 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's HG gives a positive integer N and XY tells his master the value of 2<=n<=n in Whichφ (N) is a maximum. Soon HG finds it seems a little easy for XY. Who's a primer of Lupus, because XY gives the right answer very fast B Y a small program. So HG makes some changes. For this time XY would tells him the value of 2<=n<=n for which n/φ (n) is a maximum. This time XY meets some difficult because he have no enough knowledge to solve this problem. Now he needs your help.

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

Outputfor Each test case there should is a single line of output answering the question posed above.

Sample Input210100

Sample Output630 HintIf the maximum is achieved more than once, we might pick the smallest such n.

Sourcethe 36th ACM/ICPC Asia Regional Dalian site--online Contest: First calculate the first 100 numbers; find the law; Because the numbers are too large, use Java; code:
import Java.math.biginteger;import Java.util.Scanner; Public classMain {Static intVis[] =New int[1010]; Static intP[] =New int[1010]; StaticBigInteger a[] =Newbiginteger[ the]; Static voidGetp () { for(inti =0; I <1010; i++) Vis[i]=0; vis[1] =1;  for(inti =2; I <= +; i++)        {            if(Vis[i] = =0)             for(intj = i * I; J <= +; J + =i) {vis[j]=1; }        }        intTP =0;  for(inti =1; I <= +; i++)        {            if(Vis[i] = =0) P[TP++] =i; }    }     Public Static voidMain (string[] args) {Scanner cin=NewScanner (System.inch);        GETP (); a[0]=biginteger.valueof (1);  for(intI=1; i<= -; i++) {A[i]= a[i-1].multiply (Biginteger.valueof (p[i-1])); }        intt =Cin.nextint ();  while(t-->0) {BigInteger x; X=Cin.nextbiginteger ();//for (int i = 0; I <=; i++) {//System.out.println (A[i]);//            }            if(X.compareto (Biginteger.valueof (6)) <0) {System. out. println ("2"); Continue; }             for(intI=0; i<= -; i++)            {                if(A[i].equals (x)) {System. out. println (A[i]);  Break; }                Else if(A[i].compareto (x) >0) {System. out. println (a[i-1]);  Break; }            }        }    }}

Find the maximum (regular, large number)

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.