HDU6053-TrickGCD
来源:互联网 发布:c语言 纸牌 编辑:程序博客网 时间:2024/06/11 01:24
TrickGCD
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 697 Accepted Submission(s): 266
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的乘积,这个需要优化,枚举除数,a[i]/gcd相同的为一块(现场的时候没想到这个),然后重复的用容斥搞一下就好了
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <map> #include <cmath>#include <set> #include <stack> #include <queue> #include <vector> #include <bitset> #include <functional>using namespace std;#define LL long long const int INF = 0x3f3f3f3f;const LL mod = 1000000007;int sum[100009], n;LL x[100009];LL qpow(LL x, LL y){ LL ans = 1; while (y) { if (y & 1) ans = (ans*x) % mod; y >>= 1; x = (x*x) % mod; } return ans;}int main(){ int t, cas = 1; scanf("%d", &t); while (t--) { memset(sum, 0, sizeof sum); scanf("%d", &n); for (int i = 1; i <= n; i++) { int a; scanf("%d", &a); sum[a]++; } for (int i = 1; i <= 100005; i++) sum[i] += sum[i - 1]; for (int i = 2; i <= 100000; i++) { x[i] = 1LL; for (int j = 0; j <= 100000; j += i) { int a, cnt; if (j + i - 1 > 100000) cnt = sum[100000] - sum[j - 1]; else if (j == 0) cnt = sum[j + i - 1]; else cnt = sum[j + i - 1] - sum[j - 1]; a = j / i; if (a == 0 && cnt) x[i] = 0; else if (cnt) x[i] = (x[i] * qpow(a, cnt)) % mod; } } for (int i = 100000; i >= 2; i--) { for (int j = i + i; j <= 100000; j += i) x[i] -= x[j], x[i] = (x[i] % mod + mod) % mod; } LL ans = 0; for (int i = 2; i <= 100000; i++) ans += x[i], ans %= mod; printf("Case #%d: %lld\n", cas++, ans); } return 0;}
阅读全文
0 0
- HDU6053-TrickGCD
- hdu6053 TrickGCD
- HDU6053-TrickGCD
- HDU6053 TrickGCD
- TrickGCD hdu6053
- [数论 反演] HDU6053. TrickGCD
- HDU6053 TrickGCD【数学】
- HDU6053 TrickGCD(容斥原理)
- 【HDU6053】TrickGCD(莫比乌斯容斥)
- HDU6053 TrickGCD(2017多校第2场)
- hdu6053 TrickGCD 莫比乌斯反演
- HDU6053-TrickGCD 容斥原理+莫比乌斯反演
- 【2017多校】HDU6053 TrickGCD 【莫比乌斯】
- hdu6053 TrickGCD 莫比乌斯函数 容斥原理
- 2017多校训练Contest2: 1009 TrickGCD hdu6053
- 2017杭电多校联赛第二场-TrickGCD (hdu6053)莫比乌斯容斥
- [莫比乌斯函数][分段] hdu6053 TrickGCD (2017 Multi-University Training Contest
- [莫比乌斯反演] HDU6053: [2017 多校-第2场] TrickGCD
- c++ 内联函数
- VR 原理
- 08面向对象编程风格
- Ctex初学相关
- 两种方法实现文字的移动
- HDU6053-TrickGCD
- [Java之六]数组及队列(2)
- kali linux VMwareTools 安装
- webpack 入门例子
- android中与web端的简单登录数据实现(AsyncHttpClient)
- HTML入门笔记19-HTML中Order List标签
- The Meeting Place Cannot Be Changed
- 2017 Multi-University Training Contest
- kali Linux 中文输入法配置