Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (Math, DP)
C. Little Elephant and Lcmtime limit per test4 secondsmemory limit per test256 megabytesinputstandard Inputoutputstandard Output
The Little Elephant loves the LCM (least common multiple) operation of a non-empty set of positive integers. The result of the LCM operation of K positive integers x1,? x2,?...,? x k is the minimum positive integer This is divisible by each of the numbers xi.
Let's assume that there is a sequence of integers b1,? b2,?...,? b n. Let ' s denote their LCMs as LCM(b1,? b2,?...,? b n) and the maximum of them as Max(b1,? b2,?...,? b n). The Little Elephant considers a sequence b good, if LCM(b1,? b2,?...,? b n)? =? Max (b1,?) b2,?...,? b n).
The Little Elephant has a sequence of integers a1,? a2,?...,? a N.help him find the number of good sequences of integers b1,? b2,?...,? b n, such that for all I (1?≤? I? ≤? n) The following condition fulfills:1?≤? b i? ≤? a I.as the answer can rather large, print the remainder from dividing it by 1000000007 (109?+?7).
Input
The first line contains a single positive integer n (1?≤? n? ≤?105)-the number of integers in the sequence a. The second line contains nspace-separated integers a1,? a2,?...,? a n (1?≤? ) Ai? ≤?105)-sequence a.
Output
In the single, line print a, integer-the answer to the problem modulo 1000000007 (109?+?7).
Sample Test (s)
Input
41 4 3 2
Output
15
Input
26 3
Output
13
Test instructions
Give you a sequence of a, find a b sequence, 1?≤?bi?≤?ai, make Max (BI) =LCM (BI), ask how many such bi sequences there are.
Ideas:
First to a sort, enumerate I=max (BI), to I factorization, then the part of greater than equals I very good processing, direct pow_mod () subtraction, the part of less than I arbitrarily take a constraint is enough.
Code:
#include
#include
#include
#include
#include
#include # define INF 0x3f3f3f3f#define maxn 100005#define mod 1000000007typedef long ll;using n Amespace std;int n;int a[maxn];ll pow_mod (ll x,ll N) {ll res = 1; while (n) {if (n&1) res = res * x%mod; x = x * x%mod; n >>= 1; } return res; void Solve () {int i,j; ll Ans=0,res; Sort (a+1,a+n+1); for (i=1;i<=a[n];i++)//enumeration Answer {vector
fac; for (j=1;j*j<=i;j++)//Factor {if (i%j==0) {Fac.push _back (j); if (j*j!=i) fac.push_back (i/j); }} sort (Fac.begin (), Fac.end ()); int pos,pre=1; Res=1; For (j=1;j
<>
http://www.bkjia.com/PHPjc/907369.html www.bkjia.com true http://www.bkjia.com/PHPjc/907369.html techarticle codeforces Round #157 (Div. 1) c. Little Elephant and LCM (Math, DP) c. Little Elephant and lcmtime limit per test4 secon Dsmemory limit per test256 megabytesinputstandard in ...