HDU 4196 Remoteland

Source: Internet
Author: User

Test instructions: Given an n, and then let you pick some number from the 1-n multiplication, so that the product is the largest, and the product must be a complete square number.

Idea: Will 1-n each number of decomposition factor, the power of their factor to add up, if it is even, it can constitute a complete square number, multiply, if it is odd, the explanation can not constitute, minus one is even, so minus one again multiply up. Because to decompose all the elements in the 1-n, and then multiply, then that is to decompose the n! factor, so just find out his all the factor of the power exponent is an odd number of direct except on the line. Now there is a problem that cannot be removed. To take the mold, the better way is to calculate the n!, do not multiply the prime number, then the last multiply. If it is an odd power, it is not multiplied, even power is multiplied. In this case, it is necessary to find out how many times the 1-n factor is the power, the method is to use n divided directly by the element factor, and then add up, know that n is 0. See code for details.

Spit Noisy: This test instructions completely read not understand Ah ... Read the puzzle to know. And that's the way it's amazing. Julienne

#include <cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespaceStd;typedefLong Longll;Const intMAXN =10000010;Constll mod =1000000007LL;Const intSQRTMAXN = (int) (sqrt (Double) (MAXN)) ; ll FAC[MAXN];intPRIME[MAXN];intCNT;voidinit () {memset (prime,0,sizeof(prime)); fac[0] = fac[1] =1;//factorialCNT =0;  for(inti =2; i < MAXN; i++) {Fac[i]= Fac[i-1]; if(Prime[i] = =0)//if it's prime, don't multiply.{prime[cnt++] =i; if(I <=SQRTMAXN) for(intj = i * I; J < Maxn; J + =i) prime[j]=1; }        ElseFac[i] = (fac[i] * i)% mod;//not a prime number direct multiply    }}intMain () {init (); intN;  while(~SCANF ("%d", &n) &&N) {ll ans=Fac[n];  for(inti =0; I < CNT && Prime[i] <= N; i++)        {            inttot =0, TMP = n;//power of the TMP statistic factor             while(tmp) Tot + = (tmp/=Prime[i]); if(Tot &1) ==0) ans = (ans * prime[i])%MoD; } printf ("%d\n", (int) ans); }    return 0;}
View Code

HDU 4196 Remoteland

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.