Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (數學、dp)_PHP教程

來源:互聯網
上載者:User

Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (數學、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,?...,?xk is the minimum positive integer that is divisible by each of numbers xi.

Let's assume that there is a sequence of integers b1,?b2,?...,?bn. Let's denote their LCMs as lcm(b1,?b2,?...,?bn) and the maximum of them as max(b1,?b2,?...,?bn). The Little Elephant considers a sequence b good, if lcm(b1,?b2,?...,?bn)?=?max(b1,?b2,?...,?bn).

The Little Elephant has a sequence of integers a1,?a2,?...,?an. Help him find the number of good sequences of integers b1,?b2,?...,?bn, such that for all i (1?≤?i?≤?n) the following condition fulfills: 1?≤?bi?≤?ai. As the answer can be 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,?...,?an (1?≤?ai?≤?105) — sequence a.

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



題意:
給你一個a序列,找出一個b序列,1?≤?bi?≤?ai,使得max(bi)=lcm(bi),問這樣的bi序列有多少個。

思路:
先對a排序,枚舉i=max(bi),對i因式分解,那麼大於等於i的部分很好處理,直接pow_mod()相減,小於i的部分就任意取一個約束就夠了。

代碼:
#include #include#include#include#include#include#define INF 0x3f3f3f3f#define maxn 100005#define mod 1000000007typedef long 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++) // 枚舉答案    {        vectorfac;        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 (數學、dp) C. Little Elephant and LCMtime limit per test4 secondsmemory limit per test256 megabytesinputstandard in...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.