Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (Math, DP)

Source: Internet
Author: User
Tags define contains include integer return string sort time limit
C. Little Elephant and LCM time limit/test 4 seconds memory limit per test 256 megabytes input standard input output s Tandard 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 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 to all I (1?≤? ) I≤? n) The following condition fulfills:1?≤? b i≤? a Ias the answer can is rather large, print the remainder from dividing it by 1000000007 (109?+?7).

Input

The 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" Print a single integer-the answer to the problem modulo 1000000007 (109?+?7).

Sample Test (s)
Input
4
1 4 3 2
Output
15
Input
2
6 3
Output
13
Meaning
Give you a sequence of a, find a b sequence, 1?≤?bi?≤?ai, make Max (BI) =LCM (BI), and ask how many of these bi sequences there are.
Ideas:
First to a sort, enumerated i=max (BI), to I factorization, then more than equal to I of the part is very good processing, direct pow_mod () subtraction, less than the part of I arbitrarily take a constraint is enough.
Code:
#include
  
   #include
   
    #include
    
     #include
     
      
       #include 
       
        #include 
        
         #define INF 0x3f3f3f3f #define MAXN 100005 #define MOD 1000000007 typedef lon G 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++)//enum 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 
          
           <>
           
          
         
        
      
     
    
   
  


Related Article

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.