HDU 6053 TrickGCD(分块+容斥)——2017 Multi-University Training Contest
来源:互联网 发布:泰拉瑞亚骸骨魔弓数据 编辑:程序博客网 时间:2024/05/14 05:00
传送门
TrickGCD
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2177 Accepted Submission(s): 842
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
1
4
4 4 4 4
Sample Output
Case #1: 17
题目大意:
给了一个数列
解题思路:
其实正常的思路就是想到枚举
现在考虑如何计算
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const LL MOD = 1e9+7;const int MAXN = 1e5+15;LL sum[MAXN], d[MAXN];LL Pow(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(){ ///freopen("in.txt","r", stdin); int T; scanf("%d", &T); for(int cas=1; cas<=T; cas++){ int n, x, cnt; scanf("%d", &n); int mi = MAXN, ma = -1; memset(sum, 0, sizeof sum); for(int i=0; i<n; i++) scanf("%d", &x), mi = min(mi, x), ma = max(ma, x), sum[x]++; for(int i=1; i<=ma; i++) sum[i] += sum[i-1]; for(int i=2; i<=ma; i++){ d[i] = 1; for(int j=i+i; j<=ma; j+=i){ if(i+j-1 > ma) cnt = sum[ma] - sum[j-1]; else cnt = sum[i+j-1] - sum[j-1]; if(cnt == 0) continue; d[i] = d[i] * Pow(j/i, cnt) % MOD; } } LL ans = 0; for(int i=mi; i>1; i--){//一定是从后往前计算 for(int j=i+i; j<=mi; j+=i) d[i] = (d[i] - d[j]) % MOD; ans = (ans + d[i]) % MOD; } ans = (ans % MOD + MOD) % MOD; printf("Case #%d: %lld\n",cas, ans); } return 0;}
阅读全文
0 0
- HDU 6053 TrickGCD(分块+容斥)——2017 Multi-University Training Contest
- hdu 6053 TrickGCD [2017 Multi-University Training Contest
- 2017 Multi-University Training Contest 2 && HDOJ 6053 TrickGCD 【容斥+莫比乌斯函数】
- CRT+容斥定理——Luck7 ( HDU 5768 ) ( 2016 Multi-University Training Contest 4 1005 )
- hdu 6143 容斥原理+多重集合的排列数 2017 Multi-University Training Contest
- hdu 5297 - Y sequence( 2015 Multi-University Training Contest 1)容斥原理
- HDU 5768 Lucky7(2016 Multi-University Training Contest 4 -1005)——中国剩余定理 + 容斥原理
- HDU 6038 Function(找规律)——2017 Multi-University Training Contest
- HDU 6055 Regular polygon(计算几何+思维)——2017 Multi-University Training Contest
- HDU 6048 Puzzle(找规律)——2017 Multi-University Training Contest
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
- HDU 6128 Inverse of sum(数论)——2017 Multi-University Training Contest
- HDU 3068 2017 Multi-University Training Contest
- HDU 6034 & 2017 Multi-University Training Contest
- hdu 6034 2017 Multi-University Training Contest
- HDU 3065 2017 Multi-University Training Contest
- HDU 6047 2017 Multi-University Training Contest
- HDU 6052 2017 Multi-University Training Contest
- 欧拉函数模板
- Entity.hbm.xml对象关系映射文件配置
- G
- 【RMQ】nyoj-119 士兵杀敌(三)
- 第一天:Mat类基础
- HDU 6053 TrickGCD(分块+容斥)——2017 Multi-University Training Contest
- spring-boot--使用thymeleaf模板
- hibernate.cfg.xml配置
- 迷宫 FZU
- ReLu(Rectified Linear Units)激活函数
- 谈谈 ES6 的 Promise 对象
- 建筑设计与施工VS软件设计与编程
- HADOOP(1)__Mapreduce_WordCount统计单词数
- android跨进程通信(IPC):使用AIDL