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. 51Nod 1069 Nim游戏 (位运算)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1069 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆 ...

  2. 原生js上传图片时的预览

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  3. php 使用table方式导出excel文件

    这些天在使用PHPExcel导出数据时,5000条数据竟然挂了.后来跟同事聊聊,有些明悟,PHPExcel做了很多处理,我在这里理解为渲染,就会暂用过多的空间,‘膨胀’的空间导致内存暂用过大,就挂了. ...

  4. Eclipse启动参数设置

    Eclipse启动参数设置 文件路径:安装目录根路径/eclipse.ini 参数注解: [-debug options -vm javaw.exe] 显示JVM当前内存使用量(注:详见下方<让 ...

  5. 【题解】Luogu SP8791 DYNALCA - Dynamic LCA

    原题传送门 这题用Link-Cut-Tree解决,Link-Cut-Tree详解 这道题的难点就在如何求LCA: 我们珂以先对其中一个点进行access操作,然后对另一个点进行access操作,因为L ...

  6. Python3+Dlib实现简单人脸识别案例

    Python3+Dlib实现简单人脸识别案例 写在前边 很早很早之前,当我还是一个傻了吧唧的专科生的时候,我就听说过人脸识别,听说过算法,听说过人工智能,并且也出生牛犊不怕虎般的学习过TensorFl ...

  7. Bitbucket备份恢复

    我们需要备份什么? home directory:contains  repository data, log files, plugins, and so on. database:contains ...

  8. Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心

    Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...

  9. django基础 -- 6. 多表操作

    一.多表的创建 from django.db import models # Create your models here. class Author(models.Model): id = mod ...

  10. topcoder srm 515 div1

    problem1 link 暴力枚举即可. problem2 link 一共有24小时,所以最多有24个顾客.设$f[x][y][z]$表示还剩下$x$把刀,现在时间是$y$,以及来过的顾客集合为$z ...