hdu 6053 TrickGCD 筛法
TrickGCD
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
* 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
#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 筛法的更多相关文章
- hdu 6053 TrickGCD(筛法+容斥)
TrickGCD Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- 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 | 2017 Multi-University Training Contest 2
/* HDU 6053 - TrickGCD [ 莫比乌斯函数,筛法分块 ] | 2017 Multi-University Training Contest 2 题意: 给出数列 A[N],问满足: ...
- HDU 6053 TrickGCD 莫比乌斯函数/容斥/筛法
题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd( ...
- HDU 6053 TrickGCD(莫比乌斯反演)
http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给出一个A数组,B数组满足Bi<=Ai. 现在要使得这个B数组的GCD值>=2,求共有多 ...
- HDU 6053 TrickGCD(分块)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6053 [题目大意] 给出一个数列每个位置可以取到的最大值, 问这个可以构造多少个数列,使得他们的最 ...
- HDU 6053 ( TrickGCD ) 分块+容斥
TrickGCD Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- 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 ...
- HDU 6053 TrickGCD —— 2017 Multi-University Training 2
TrickGCD Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
随机推荐
- bzoj4358 premu
题目链接 莫队算法 没有用线段树,而是看了showson的并查集%%% #include<algorithm> #include<iostream> #include<c ...
- 监控MySQL主从脚本
示例一: cat check_mysql_health #!/bin/sh slave_is=($(mysql -S /tmp/mysql3307.sock -uroot -e "show ...
- django 上传文件及反馈信息
from django.shortcuts import render,HttpResponse from django.views import View from Fiskars.models i ...
- 给PHP开启shmop扩展实现共享内存
在项目开发中,想要实现PHP多个进程之间共享数据的功能,让客户端连接能够共享一个状态,需要开启共享内存函数shmop.如果预期考虑会遇到这方面需求,那么最好在编译PHP的时候添加--with-shmo ...
- collectd 检测cpu使用率
环境配置 1. install epel https://www.cyberciti.biz/faq/installing-rhel-epel-repo-on-centos-redhat-7-x/ 2 ...
- CC攻击介绍及如何防御
CC攻击介绍 CC攻击(Challenge Collapsar)是DDOS(分布式拒绝服务)的一种,前身名为Fatboy攻击,也是一种常见的网站攻击方法.攻击者借助代理服务器生成指向受害主机的合 ...
- 如何获取sdcard的总容量
activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...
- VC++ 使用CreateProcess创建新进程
https://www.cnblogs.com/fancing/p/6477918.html #include <windows.h> #include <tchar.h> # ...
- [error] 2230#2230: *84 client intended to send too large body: 1711341 bytes
centos7 lnmp部署知乎上传主体报错 2019/01/17 18:55:27 [error] 2230#2230: *89 open() "/code/wordpress/favic ...
- 配置vim
VundleVuldle是一个全自动的插件管理器,让我们通过维护插件列表的方式管理插件.它为安装.更新.删除插件提供了方便的命令.在安装Git的情况下(本文不赘述Git的安装),输入命令: git c ...