HDU 4002 Find The maximum (the properties of Euler function-integrable function (the second problem of the network competition of Dalian 2011)

Source: Internet
Author: User

"Topic link": Click here~~

"To the effect of the topic":

Given an integer n, a number x,x between 1 and N, and x/φ (x) is the largest (where φ (x) is the Euler function of x).
"Ideas":

The Euler function is an integrable function, namely: ifThen there are:
and:


Then there are:


To make F (x) the largest, the x must contain as many different prime factors as possible.

Code:

/* * problem:hdu no.4002* Running time:1700ms * Complier:java * Author:javaherongwei * Create time:0:08 Wednesday, 2015/9/23 */import java.util.*;import java.io.*;import java.math.*;import java.math.biginteger;p Ublic class Main{public static void Main (String args[]) {Scanner cin = new Scanner (new Bufferedinputstream (system.in)); fin Al int n=100005;boolean[] ok=new boolean[n];int [] prime= new int [N];int cnt=0; BigInteger [] fac= new BigInteger [65];for (int i=0; i<n; ++i) Ok[i]=false; Linear sieve method for (int i=2; i<n; ++i) {if (!ok[i]) prime[cnt++]=i;for (int j=0; j<cnt&&i*prime[j]<n; ++j) {ok[i* prime[j]]= true;if (i%prime[j]==0) break;}} fac[0]=biginteger.one;for (int i=1; i<=60; ++i) {fac[i]=fac[i-1].multiply (biginteger.valueof (prime[i-1]));} BigInteger n;int T;t=cin.nextint (), while (t-->0) {N=cin.nextbiginteger (), for (int i=1; i<=60; ++i) {if (fac[i+1] . CompareTo (n) >0) {System.out.println (fac[i]); break;}}}} 



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4002 Find The maximum (the properties of Euler function-integrable function (the second problem of the network competition of Dalian 2011)

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.