HDU6053 TrickGCD(2017多校第2场)
来源:互联网 发布:广电网络中山分公司 编辑:程序博客网 时间:2024/06/06 05:06
TrickGCD
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1218 Accepted Submission(s): 464
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
*
* For each pair( l , r ) (
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 arrayA .
Then a line containsn numbers describe each element of A
You can assume that1≤n,Ai≤105
Each test case begins with an integer number n describe the size of array
Then a line contains
You can assume that
Output
For the k th 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
144 4 4 4
Sample Output
Case #1: 17
Source
2017 Multi-University Training Contest - Team 2
—————————————————————————————————
题意:给你n个数字,每个位置的数字可以小于等于a[i],求所有gcd(l,r)都满足大于等于2的情况数
解题思路:枚举gcd的情况,每种gcd的情况等于所有a[i]/gcd的乘积,但这显然会超,所以需要优化,我们可以分块处理,如枚举5时,5 6 7 8 9对应的都是1个,所以我们可以按gcd分块,而且越大块越少,快内用快速幂加速。 得到一个dp数组dp[i]表示gcd为i的方案数,最后容斥搞一搞
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <set>#include <map>using namespace std;#define LL long longconst LL mod=1e9+7;const int INF=0x3f3f3f3f;#define MAXN 100005int pre[MAXN];LL a[MAXN];LL dp[MAXN];LL qpow(LL a,LL b){ LL ans=1; while(b) { if(b&1) ans=(ans*a)%mod; b>>=1,a=(a*a)%mod; } return ans;}int main(){ int T,n; int q=1; for(scanf("%d",&T); T--;) { scanf("%d",&n); memset(pre,0,sizeof pre); for(int i=0; i<n; i++) { scanf("%lld",&a[i]); pre[a[i]]++; } for(int i=1; i<MAXN; i++) pre[i]+=pre[i-1]; for(int i=2; i<MAXN; i++) { dp[i]=1LL; for(int j=0; j<MAXN; j+=i) { int cnt; if (j == 0) cnt = pre[j + i - 1]; else if (j + i - 1 > 100000) cnt = pre[100001] - pre[j - 1]; else cnt=pre[j+i-1]-pre[j-1]; if(j/i==0&&cnt) {dp[i]=0;break;} dp[i]=(dp[i]*qpow(j/i,(LL)cnt))%mod; } } LL ans=0; for(int i=a[n-1]; i>1; i--) { for(int j=i+i; j<=a[n-1]; j+=i) { dp[i]-=dp[j]; dp[i]=(dp[i]%mod+mod)%mod; } ans+=dp[i]; ans%=mod; } printf("Case #%d: %lld\n",q++,ans); } return 0;}
阅读全文
0 0
- HDU6053 TrickGCD(2017多校第2场)
- [莫比乌斯反演] HDU6053: [2017 多校-第2场] TrickGCD
- 2017杭电多校联赛第二场-TrickGCD (hdu6053)莫比乌斯容斥
- HDU6053-TrickGCD
- hdu6053 TrickGCD
- HDU6053-TrickGCD
- HDU6053 TrickGCD
- TrickGCD hdu6053
- TrickGCD————(hdu6053)2017多校(莫比乌斯容斥)
- [数论 反演] HDU6053. TrickGCD
- HDU6053 TrickGCD【数学】
- 【2017多校】HDU6053 TrickGCD 【莫比乌斯】
- 2017多校训练Contest2: 1009 TrickGCD hdu6053
- HDU6053 TrickGCD(容斥原理)
- 【HDU6053】TrickGCD(莫比乌斯容斥)
- [莫比乌斯函数][分段] hdu6053 TrickGCD (2017 Multi-University Training Contest
- hdu6053 TrickGCD 莫比乌斯反演
- 2017 杭电多校联赛第二场 1009 TrickGCD(容斥原理) HDU 6053
- Android--------在fragment滚动播放
- Protobuf-swift 集成小结 韩俊强的博客
- TCP BBR拥塞控制算法解析
- CTeX 中 MiKTeX 太旧,无法更新宏包解决方案
- Annotation注解归总&ID生成策略&联合主键及hql中的条件查询写法
- HDU6053 TrickGCD(2017多校第2场)
- linux安装jdk mysql tomcat之部署项目
- 图像处理基本概念(模板,卷积运算)
- 原型和作用域
- <Android 基础(三十七)> 自定义ViewPagerIndicator
- 树链剖分小结板子
- iDesktop点数据集构建DEM时三种插值方式的选择
- 深度学习笔记---规范化
- fairyguiUI适配问题