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&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