CodeforcesRound #157 (Div.1) C. LittleElephantandLCM (Mathematics, dp) _ PHP Tutorial

Source: Internet
Author: User
CodeforcesRound #157 (Div.1) C. LittleElephantandLCM (Mathematics, dp ). CodeforcesRound #157 (Div.1) C. LittleElephantandLCM (Mathematics, dp) C. parse Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (Mathematics, 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 operationKPositive integersX1 ,?X2 ,?...,?XKIs the minimum positive integer that is pisible by each of numbersXI.

Let's assume that there is a sequence of integersB1 ,?B2 ,?...,?BN. Let's denote their LCMsLcm(B1 ,?B2 ,?...,?BN) And the maximum of themMax(B1 ,?B2 ,?...,?BN). The Little Elephant considers a sequenceBGood, ifLcm(B1 ,?B2 ,?...,?BN)? =?Max(B1 ,?B2 ,?...,?BN).

The Little Elephant has a sequence of integersA1 ,?A2 ,?...,?AN. Help him find the number of good sequences of integersB1 ,?B2 ,?...,?BN, Such that for allI(1? ≤?I? ≤?N) The following condition fulfills: 1? ≤?BI? ≤?AI. As the answer can be rather large, print the remainder from piding it by 1000000007 (109? +? 7 ).

Input

The first line contains a single positive integerN(1? ≤?N? ≤? 105)-the number of integers in the sequenceA. The second line containsNSpace-separated integersA1 ,?A2 ,?...,?AN(1? ≤?AI? ≤? 105)-sequenceA.

Output

In the single line print a single 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
 
 
 
Question:
Let's give you a sequence a and find a sequence B, 1? ≤? Bi? ≤? Ai, so that max (bi) = lcm (bi), ask how many such bi sequences there are.
 
Ideas:
Sort a first, enumerate I = max (bi), and break down the I-type decomposition. the part greater than or equal to I is well processed, and the pow_mod () is directly subtracted, if the number is smaller than I, any constraint is enough.
 
Code:
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
       
# Include # define INF 0x3f3f3f # define maxn 100005 # define mod 1000000007 typedef long ll; using namespace 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 ++) // enumerated 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.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/907369.htmlTechArticleCodeforces Round #157 (Div. 1) C. Little Elephant and LCM (Mathematics, dp) C. Little Elephant and LCMtime limit per test4 secondsmemory limit per test256 megabytesinputstandard in...

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.