hdu 6053

Description

You are given an array A , and Zhu wants to know there are how many different array B satisfy the following conditions?

  • 1BiAi
  • For each pair(l,r) (1lrn) , gcd(bl,bl+1...br)2

 

Input

The first line is an integer T(1T10) describe the number of test cases.

Each test case begins with an integer number n describe the size of array A .

Then a line contains n numbers describe each element of A

You can assume that 1n,Ai105

 

Output

For the kth test case , first output “Case #k: ” , then output an integer as answer in a single line . because the answer may be large , so you are only need to output answer mod 109+7

 

Sample Input

1
4
4 4 4 4

 

Sample Output

Case #1: 17

 

题意

给出数组 A ,问有多个种 B 数组满足所给条件。

 

思路

针对条件,我们可以枚举 gcd ,显然对于每一个素因子 i 在范围 [i,j] 下共有 ji 个数可以整除它,假设 A 中共有 cnt 个数字处于 [j,j+i1] 这个范围内,这也就相当于有 cnt 个位置的数可以在 ji 个因子中随意变动,共有 (ji)cnt 种方案,而对于每一个因子,其结果为 i|j(ji)cnt

最终通过容斥或者莫比乌斯去掉重复部分即可。

 

AC 代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include<iostream>
using namespace std ;

#define inf 0x3f3f3f
typedef __int64 LL;
const int maxn = 1e5+10;
const int mod = 1e9+7;
LL mu[maxn];
LL sum[maxn<<1];
LL cnt[maxn<<1];

void init()
{
    mu[1]=1;
    for(int i=1; i<maxn; i++)
        for(int j=i+i; j<maxn; j+=i)
            mu[j]-=mu[i];
}

LL mult(LL a,LL n)
{
    LL res=1;
    while(n)
    {
        if(n&1)res=(res*a)%mod;
        a=(a*a)%mod;
        n>>=1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    init();
    int T;
    cin>>T;
    for(int ti=1; ti<=T; ti++)
    {
        int n,minn=inf;
        memset(cnt,0,sizeof(cnt));
        cin>>n;
        for(int i=0; i<n; i++)
        {
            int x;
            cin>>x;
            cnt[x]++;
            minn=min(minn,x);
        }
        LL ans=0;
        for(int i=1; i<maxn*2; i++)
            sum[i]=sum[i-1]+cnt[i];
        for(int i=2; i<=minn; i++)
        {
            LL temp=1LL;
            if(mu[i])
            {
                for(int j=i; j<maxn; j+=i)
                    temp=(temp*mult(j/i,sum[j+i-1]-sum[j-1]))%mod;
            }
            ans=(ans-temp*mu[i]+mod)%mod;
        }
        cout<<"Case #"<<ti<<": "<<ans<<endl;
    }
    return 0;
}
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值