HDU 6053 ( TrickGCD ) 分块+容斥
TrickGCD
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 3401 Accepted Submission(s): 1268
* 1≤Bi≤Ai
* For each pair( l , r ) (1≤l≤r≤n) , gcd(bl,bl+1...br)≥2
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
4
4 4 4 4
#include<bits/stdc++.h>
#define db double
#define ll long long
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1e5+;
const int mod=1e9+;
const int MOD=mod-;
const db eps=1e-;
const int inf = 0x3f3f3f3f;
ll a[N];
ll sum[N];
ll qpow(ll x,ll n)
{
ll ans=;x%=mod;
for(;n>;n>>=){if(n&) ans=(ans*x)%mod;x=x*x%mod;}
return ans;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
int t;
ci(t);
for(int ii=;ii<=t;ii++)
{
int n,x,ma=-N,mi=N;
memset(sum,,sizeof(sum));
ci(n);
for(int i=;i<n;i++)
ci(x),sum[x]++,ma=max(ma,x),mi=min(mi,x);
for(int i=;i<=ma;i++) sum[i]+=sum[i-];//统计小于等于i的数字的个数
for(int i=;i<=mi;i++){//从2~mi枚举gcd
a[i]=;
for(int j=i;j<=ma;j+=i){//分区间计算
int c;
if(i+j-<=ma) c=sum[i+j-]-sum[j-];
else c=sum[ma]-sum[j-];
if(!c) continue;
a[i]=(a[i]*qpow(j/i,c))%mod;
}
}
ll ans=;
for(int i=mi;i>=;i--)
{
for(int j=i+i;j<=mi;j+=i) a[i]=(a[i]-a[j])%mod;//减掉确定的倍数
a[i]=(a[i]+mod)%mod;
ans=(ans+a[i])%mod;
}
printf("Case #%d: %lld\n",ii,ans);
}
}
HDU 6053 ( TrickGCD ) 分块+容斥的更多相关文章
- hdu 6053 TrickGCD(筛法+容斥)
TrickGCD Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- hdu 6053 trick gcd 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给定一个数组,我们定义一个新的数组b满足bi<ai 求满足gcd(b1,b2....bn)&g ...
- 2017ACM暑期多校联合训练 - Team 2 1009 HDU 60563 TrickGCD (容斥公式)
题目链接 Problem Description You are given an array A , and Zhu wants to know there are how many differe ...
- HDU 6053 TrickGCD 莫比乌斯函数/容斥/筛法
题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd( ...
- HDU 5213 分块 容斥
给出n个数,给出m个询问,询问 区间[l,r] [u,v],在两个区间内分别取一个数,两个的和为k的对数数量. $k<=2*N$,$n <= 30000$ 发现可以容斥简化一个询问.一个询 ...
- HDU 6053 - TrickGCD | 2017 Multi-University Training Contest 2
/* HDU 6053 - TrickGCD [ 莫比乌斯函数,筛法分块 ] | 2017 Multi-University Training Contest 2 题意: 给出数列 A[N],问满足: ...
- 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 ...
- HDU 6053 TrickGCD(分块)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6053 [题目大意] 给出一个数列每个位置可以取到的最大值, 问这个可以构造多少个数列,使得他们的最 ...
- HDU 6053 TrickGCD(莫比乌斯反演)
http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给出一个A数组,B数组满足Bi<=Ai. 现在要使得这个B数组的GCD值>=2,求共有多 ...
随机推荐
- 打印流-PrintStream
打印流-PrintStream java.io.PrintStream为其他输出流添加了功能,使其他的流能够更方便的打印各种数据值表现形式 PrintStream特点: 1.只负责数据的输入,不负责数 ...
- <checking for mysql_config not found>
php 5.3.29编译安装排错: ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --w ...
- node线程有多少
一篇文章构建你的 NodeJS 知识体系
- IDEA运行时报错(IDEA不识别新语法):Error:java: Compilation failed: internal java compiler error
File-->setting...-->Buil,Execution,Deployment-->Compiler-->Java Compiler中,改一下Module,我的原来 ...
- 如何从MYSQL官方YUM仓库安装MYSQL5.x 原理一样只要获取对的仓库依赖安装对的仓库依赖就ok了,我就是用这种安装的5.7
如何从MYSQL官方YUM仓库安装MYSQL5.6 2013年10月,MySQL开发团队正式宣布支持Yum仓库,这就意味着我们现在可以从这个Yum库中获得最新和最优版的MySQL安装包.本文将在一台全 ...
- JavaScript获取URL参数公共方法
写一个JavaScript获取URL参数的通用方法,可以把它放到常用方法的JS文件中调用,直接上代码例子,新手可以学习一下! <!DOCTYPE html> <html lang=& ...
- @Enable*注解的工作原理
@EnableAspectJAutoProxy @EnableAsync @EnableScheduling @EnableWebMv @EnableConfigurationProperties @ ...
- 查看mysql历史命令
默认情况下操作mysql会在家目录下创建一个隐藏的mysql历史命令文件.mysql_history 在管理授权mysql账户时也会记录这些明文密码到这个文件,非常的不安全 [root@localho ...
- COGS 1453. [USACO NOV]空牛栏
★★ 输入文件:empty.in 输出文件:empty.out 简单对比时间限制:1 s 内存限制:64 MB [题目描述] FJ建的新牛棚里有N(2<=N<=3,000, ...
- ffmeg过滤器介绍[转]
在ffmpeg中,进行反交错需要用到avfilter,即图像过滤器,ffmpeg中有很多过滤器,很强大,反交错的过滤器是yadif. 基本的过滤器使用流程是: 解码后的画面--->buffer过 ...