标签:des style blog color java os io strong
3 3 3 3 3 3 3 5 3 1 2 3
7 1 0 59 3 0 1 1HintIn the first test case : when d = 1, {b} can be : (1, 1, 1) (1, 1, 2) (1, 2, 1) (1, 2, 2) (2, 1, 1) (2, 1, 2) (2, 2, 1) when d = 2, {b} can be : (2, 2, 2) And because {b} must have exactly K number(s) different from {a}, so {b} can‘t be (3, 3, 3), so Answer = 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 300000+10;
const int MOD = 1000000007;
typedef long long ll;
int n,m,k;
int num[maxn];
ll Cot[maxn];
ll cnt[maxn];
ll ans[maxn];
inline void gcd(int a,int b,int& d,int &x,int &y){
if(!b){
d = a; x = 1;y = 0;
}else{
gcd(b,a%b,d,y,x);
y -= x*(a/b);
}
}
inline ll inv(int a){
int d,x,y;
gcd(a,MOD,d,x,y);
return d == 1? (x+MOD)%MOD:-1;
}
inline ll pow_mod(int a,int b){
if(b < 0) return 0;
if(a==1) return 1;
ll ret = 1,pow = a;
while(b){
if(b&1) ret = (ret*pow)%MOD;
pow = (pow*pow)%MOD;
b >>= 1;
}
return ret;
}
int main(){
while(~scanf("%d%d%d",&n,&m,&k)){
ll ret = 0;
bool flag = true;
memset(cnt,0,sizeof cnt);
Cot[n-k] = 1;
int tmp = n-k;
for(int i = n-k+1; i <= n; i++){
Cot[i] = (Cot[i-1]*i)%MOD*inv(i-tmp)%MOD;
}
for(int i = 1; i <= n; i++){
scanf("%d",&num[i]);
cnt[num[i]]++;
}
for(int i = m; i >= 1; i--){
int sum = cnt[i],che = 0;
for(int j = i+i; j <= m; j += i){
sum += cnt[j];
che = (ans[j]+che)%MOD;
}
if(sum < tmp) ans[i] = 0;
else{
int d = m/i;
ans[i] = Cot[sum]*pow_mod(d-1,sum-tmp)%MOD*pow_mod(d,n-sum)%MOD;
ans[i] = (ans[i]-che+MOD)%MOD;
}
}
printf("%I64d",ans[1]);
for(int i = 2; i <= m; i++){
printf(" %I64d",ans[i]);
}
printf("\n");
}
return 0;
}
HDU4675-GCD of Sequence(数论+组合计数),布布扣,bubuko.com
HDU4675-GCD of Sequence(数论+组合计数)
标签:des style blog color java os io strong
原文地址:http://blog.csdn.net/mowayao/article/details/38440655