TrickGCD

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

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

* 1≤Bi≤Ai
* For each pair( l , r ) (1≤l≤r≤n) , gcd(bl,bl+1...br)≥2

 
Input
The first line is an integer T(1≤T≤10) 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 1≤n,Ai≤105

 
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
 
Source
 
Recommend
liuyiding
题意:给你n个数字,每个位置的数字可以小于等于a[i],求所有gcd(l,r)都满足大于等于2的情况数;
思路:显然枚举gcd的情况,对于每个位置都有a[i]/gcd的个数可以满足条件,gcd的情况的所有a[i]/gcd的乘积;
   这个也需要优化,枚举除数,a[i]/gcd相同的为一块,nlong(n)的复杂度*快速幂的log,后面的用容斥筛一下就好了;
   莫比乌斯好像也可以。
 
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-4
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=1e9+,MOD=1e9+;
const LL INF=1e18+,mod=1e9+; int a[N],sum[N];
LL dp[N],num[N];
LL qpow(LL a,LL b,LL c)
{
LL ans=;
while(b)
{
if(b%)ans=(ans*a)%c;
b>>=;
a=(a*a)%mod;
}
return ans;
}
int main()
{
int n;
int T,cas=;
scanf("%d",&T);
while(T--)
{
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
a[x]++;
}
for(int i=;i<=;i++)
sum[i]=sum[i-]+a[i];
for(int i=;i<=;i++)//枚举除数
{
num[i]=1LL;
for(int j=;j<=;j+=i)
{
int b;
if(j+i->)b=sum[]-sum[j-];
else if(j==) b=sum[j+i-];
else b=sum[j+i-]-sum[j-];
int a=j/i;
if(a==&&b)num[i]=;
else if(b)num[i]=(num[i]*qpow(a,b,mod))%mod;
}
}
for(int i=;i>=;i--)
{
dp[i]=num[i];
for(int j=i+i;j<=;j+=i)
dp[i]-=dp[j],dp[i]=(dp[i]%mod+mod)%mod;
}
LL ans=;
for(int i=;i<=;i++)
ans+=dp[i],ans%=mod;
printf("Case #%d: %lld\n",cas++,ans); }
return ;
}

hdu 6053 TrickGCD 筛法的更多相关文章

  1. hdu 6053 TrickGCD(筛法+容斥)

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  2. 2017 多校2 hdu 6053 TrickGCD

    2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...

  3. HDU 6053 - TrickGCD | 2017 Multi-University Training Contest 2

    /* HDU 6053 - TrickGCD [ 莫比乌斯函数,筛法分块 ] | 2017 Multi-University Training Contest 2 题意: 给出数列 A[N],问满足: ...

  4. HDU 6053 TrickGCD 莫比乌斯函数/容斥/筛法

    题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd( ...

  5. HDU 6053 TrickGCD(莫比乌斯反演)

    http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给出一个A数组,B数组满足Bi<=Ai. 现在要使得这个B数组的GCD值>=2,求共有多 ...

  6. HDU 6053 TrickGCD(分块)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6053 [题目大意] 给出一个数列每个位置可以取到的最大值, 问这个可以构造多少个数列,使得他们的最 ...

  7. HDU 6053 ( TrickGCD ) 分块+容斥

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  8. 2017 Multi-University Training Contest - Team 2 &&hdu 6053 TrickGCD

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  9. HDU 6053 TrickGCD —— 2017 Multi-University Training 2

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

随机推荐

  1. [转载]C# 常用日期时间函数(老用不熟)

    原博地址:http://www.jb51.net/article/20181.htm --DateTime 数字型 System.DateTime currentTime=new System.Dat ...

  2. java操作linux 提交spark jar

    maven依赖 <!--Java ssh-2 --><dependency> <groupId>ch.ethz.ganymed</groupId> &l ...

  3. The Little Prince-12/17

    The Little Prince-12/17 今年四六级吐槽,说到做到!!!文思泉涌了兄弟们! “这就是你自己的错了,我本来并不想给你带来任何痛苦的,可你却要我驯服你……可你要哭了,可你什么好处也没 ...

  4. 怎样从外网访问内网WebSphere?

    本地安装了一个WebSphere,只能在局域网内访问,怎样从外网也能访问到本地的WebSphere呢?本文将介绍具体的实现步骤. 准备工作 安装并启动WebSphere 默认安装的WebSphere端 ...

  5. PHP中array_map与array_column之间的关系分析

    array_map()与array_column()用法如下: array_map();将回调函数作用到给定数组的单元上array_column();快速实现:将二维数组转为一维数组 array_co ...

  6. OSI七层协议与TCP/IP模型

    OSI为Open System Interconnection的缩写,意为开放式系统互联,国际标准化组织(ISO,International Organization for Standardizat ...

  7. P2801 教主的魔法(分块)

    P2801 教主的魔法 区间加法,区间查询 显然就是分块辣 维护一个按块排好序的数组. 每次修改依然是整块打标记,零散块暴力.蓝后对零散块重新排序. 询问时整块二分,零散块暴力就好辣 注意细节挺多和边 ...

  8. 这五件事,二次SaaS创业的老炮儿都在做(转)

    在我看来,我们现在正处在SaaS公司发展过程中的第三代.第一代SaaS公司有Salesforce.Netsuite和Webex等.紧接着兴起的第二代SaaS公司大多都是利用Salesforce或其他网 ...

  9. linux有趣的命令screen

    screen类似一个容器, 可以把当前前台运行的应用shell窗口关闭而不影响运行, 跟后后nohup有点相似, 不过我觉得比nohup还好用 用法1: screen 然后会弹出一个新的shell窗口 ...

  10. Thinkphp5 分页带参数

    原文链接:http://www.zhaisui.com/article/51.html