"Number theory" [Cf258c]little Elephant and LCM

Source: Internet
Author: User

Topic
Analysis: Enumerate the maximum number, and then find it all factor p1.......pk, choose some number from any of these numbers, the number of lcm| this number and, the number of the largest LCM is the enumeration of this number, and if pi<=aj<=pi+1 the number of former I can be placed in the position J, That is, J this position has CJ species choice, the total plan number is C1*C2*......*CJ
As an optimization, for each pi, we enumerate the number of AJ satisfies pi<=aj<=pi+1 as QI, then there are ans=1^qi*2^qi*......*q^qk, but these scenarios contain cases where the maximum number is not selected, the last item should be q^qk-(q-1) ^qk

Code:

#include <cstdio>#include <algorithm>#include <cmath>using namespace STD;#define MAXN 100000#define MOD 1000000007Long Longa[maxn+Ten],n,p[maxn+Ten],cnt,ans;voidRead (Long Long&AMP;X) {CharC while((C=getchar ()) &&c!=eof) {if(c>=' 0 '&&c<=' 9 ') {x=c-' 0 '; while((C=getchar ()) &&c>=' 0 '&&c<=' 9 ') x=x*Ten+c-' 0 '; UNGETC (C,stdin);return; }    }}voidIsfactor (Long LongN) {Long Longt=sqrt(n+0.5), I; Cnt=0; for(i=1; i<=t;i++)if(n%i==0) P[++cnt]=i;    i=cnt; cnt*=2;if(t*t==n) CNT--, i--; for(; i;i--) {p[cnt-i+1]=n/p[i]; }}Long Long POW(Long LongALong Longb) {Long Longret=1; while(b) {if(b&1) Ret=ret*a%mod; b>>=1;    A=a*a%mod; }returnRET;}intMain () {Long LongI,j,k,t,s; Read (n); for(i=1; i<=n;i++) Read (A[i]); Sort (A +1, a+n+1); for(i=1; i<=a[n];i++) {isfactor (i); t=0; s=1; for(j=2; j<=cnt;j++) {K=lower_bound (A +1, a+n+1, P[j])-a-1; s=s*POW(J-1, k-t)%mod;        T=k; } s=s* (POW(CNT,N-T)-POW(cnt-1, n-t))%mod;    Ans= (ans+s)%mod; }printf("%i64d\n", ans);}

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

"Number theory" [Cf258c]little Elephant and LCM

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.