Codeforces-258C:Little Elephant and LCM(数论)
来源:互联网 发布:mac版qq接收文件 编辑:程序博客网 时间:2024/05/21 11:28
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).
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.
In the single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
41 4 3 2
15
26 3
13
如:a=[1, 2 ,3 ,4 ] 4
枚举最大值 2,2,2
首先是4,a数列中各数包含4的因子分别为 1,1,1,1 ,那么最大值为4时的b数列的方案数为1*2*2*(4-3)=4种。因为要满足最大值为4,所以最后只能取4.
3,3
其次是3,a数列中各数包含3的因子分别为 1,1 ,1,1 ,那么最大值为3时的b数列的方案数为1*1*(2*2-1)=3种。因为要满足最大值为3,所以最后有3种取法。
以此类推。
#include<bits/stdc++.h>typedef __int64 ll;using namespace std;const int MOD=1e9+7;const int MAX_N = 1e6;int all=0,p[MAX_N],m;int pr[MAX_N+100],a[MAX_N];bool isp[MAX_N+10];void init(){all = 0;memset(isp,0,sizeof isp);isp[1]=1;for(int i=2;i<=MAX_N;i++){if(!isp[i])pr[all++] = i;for(int j=0;j<all;j++){ll t = (ll)1*pr[j]*i ;if(t<=MAX_N){isp[t] = true;if(i%pr[j]==0)break;}else break;}}}void dive(int x){ m=0; for(int i=1;i*i<=x;i++) { if(x%i==0) { p[m++]=i; if(x/i!=i)p[m++]=x/i; } } sort(p+1,p+m);}ll POW(ll x,ll y){ ll res=1; while(y) { if(y&1)res=res*x%MOD; x=(x*x)%MOD; y/=2; } return res%MOD;}int main(){ init(); int n; scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d",&a[i]); sort(a,a+n); ll ans=0; for(int i=a[n-1];i>=1;i--) { dive(i); ll st=0,now=1; for(int j=1;j<m;j++) { ll en=lower_bound(a,a+n,p[j])-a; now=now*POW(j,en-st)%MOD; st=en; } now=now*(((POW(m,n-st)-POW(m-1,n-st))%MOD+MOD)%MOD)%MOD; ans=(ans+now)%MOD; } cout<<ans<<endl;}
- Codeforces-258C:Little Elephant and LCM(数论)
- 【数论】[CF258C]Little elephant and LCM
- Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp)
- codeforces 220c Little Elephant and Shifts
- codeforces 221C Little Elephant and Problem
- Codeforces-258B Little Elephant and Elections
- Codeforces 258B Little Elephant and Elections
- Codeforces 258B - Little Elephant and Elections
- Codeforces Round #157 (Div. 1), problem: (C) Little Elephant and LCM DP+组合数学 0(n^(5/2))
- CodeForces258C Little Elephant and LCM(数学推理)
- <codeforces>Little Elephant and Sorting
- [Codeforces 204C] Little Elephant and Furik and Rubik (期望)
- Codeforces Round #136 (Div. 2) C. Little Elephant and Problem
- codeforces 258B Little Elephant and Elections 数位DP+DFS
- CodeForces 258B Little Elephant and Elections 数位DP
- codeforces 258B - Little Elephant and Elections 数位DP
- codeforces 258-E. Little Elephant and Tree 线段树,离线
- codeforces 258B Little Elephant and Elections 数位DP+排列组合
- 深拷贝、浅拷贝
- 2017
- SDUT-2676 3-7 类的友元函数的应用
- Maven多项目
- eclipse中git pull拉取报错Checkout conflict with files
- Codeforces-258C:Little Elephant and LCM(数论)
- java_se 抽象类(包含多态知识)
- 【BZOJ1010】【HNOI2008】玩具装箱
- day03-asyUI中validatebox使用
- hibernate 工作原理 以及作用
- Package与Import
- SDK-tools安装
- Vue项目步骤
- dlib——机器学习工具箱