Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp)_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:54:39
原创
1376人浏览过

C. Little Elephant and LCM

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

豆包爱学
豆包爱学

豆包旗下AI学习应用

豆包爱学 674
查看详情 豆包爱学

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的部分就任意取一个约束就够了。
登录后复制
代码:
登录后复制
<pre name="code" class="n">#include <iostream>#include<cstring>#include<cstdio>#include<string>#include<vector>#include<algorithm>#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++) // 枚举答案    {        vector<int>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<fac.size();j++)        {            pos=lower_bound(a+1,a+n+1,fac[j])-a;            res*=pow_mod(j,pos-pre);            res%=mod;            pre=pos;        }        ans+=res*((pow_mod(j,n-pre+1)-pow_mod(j-1,n-pre+1)+mod)%mod);        ans%=mod;    }    printf("%I64d\n",ans);}int main(){    int i,j;    while(~scanf("%d",&n))    {        for(i=1;i<=n;i++)        {            scanf("%d",&a[i]);        }        solve();    }    return 0;}
登录后复制
HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号