2017 多校2 hdu 6053 TrickGCD

题目:

You are given an array \(A\) , and Zhu wants to know there are how many different array \(B\) satisfy the following conditions?

  • \(1≤B_i≤A_i\)
  • For each pair(\(l , r) (1≤l≤r≤n) , gcd(bl,bl+1...br)≥2\)

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 array \(A\).

Then a line contains \(n\) numbers describe each element of \(A\)

You can assume that \(1≤n,A_i≤10^{5}\)

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 \(10^{9}+7\)

思路:

枚举\(g = gcd(b_1,b_2,....,b_n)\),
那么\(gcd为g\)的倍数的答案就是\(\prod_{i=1}^{n}\frac{A_i}{g}\)
每次暴力计算是不行的,想到一个数在\(g到2g-1\)除以g结果是不变的
所以可以预处理区间数字个数的前缀和,\(O(nlogn)\)类似素数筛法预处理出每个\(g\)的答案
现在要计算\(gcd为g\)的答案,我们从大到小枚举,同时更新它的约数的答案,就可以保证不重复了
从小到大枚举过去就要用到莫比乌斯函数去计算了
\(令F(i)为gcd为i的倍数的方案数,f(i)为gcd为i的方案数\)
\(F(i) = \sum_{i|d}^{}{f(d)} \rightarrow f(i) = \sum_{i|d}u(\frac{d}{i})F(d)\)
代码贴的是比赛时过的姿势

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
vector<int> v[N];
int n;
int sum[N],ans[N];
void init(){for(int i = 2;i < N;i++){for(int j = i;j < N;j+=i) v[j].push_back(i);}
}
int qpow(int x,int y){int ans = 1;while(y){if(y&1) ans = 1LL* ans * x % mod;x = 1LL * x * x % mod;y >>= 1;}return ans;
}
int main(void)
{init();int T, x;int cas = 1;cin>>T;while(T--){memset(sum, 0, sizeof(sum));scanf("%d",&n);int mi = N;for(int i = 1;i <= n;i++) {scanf("%d",&x);mi = min(x,mi);sum[x]++;}for(int i = 1;i < N;i++) sum[i]+=sum[i-1];for(int i = 2;i <= mi;i++){ans[i] = 1;for(int j = i;j < N;j+=i){int l = j + i - 1 > N - 1?N-1:j + i - 1;ans[i] = 1LL * ans[i] * qpow(j / i,sum[l] - sum[j - 1]) % mod;}}int res = 0;for(int i = mi;i >= 2;i--){res = (res + ans[i])%mod;for(int j = 0;j < v[i].size();j++) ans[v[i][j]] = (ans[v[i][j]] - ans[i] + mod)%mod;}printf("Case #%d: %d\n",cas++,res);}return 0;
}

转载于:https://www.cnblogs.com/jiachinzhao/p/7267453.html

2017 多校2 hdu 6053 TrickGCD相关推荐

  1. hdu 6053 TrickGCD

    Problem acm.hdu.edu.cn/showproblem.php?pid=6053 莫比乌斯反演介绍 莫比乌斯反演(by PoPoQQQ) 莫比乌斯反演入门 莫比乌斯反演 Referenc ...

  2. 2017 多校3 hdu 6061 RXD and functions

    2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...

  3. hdu6103[尺取法] 2017多校6

    /*hdu6103[尺取法] 2017多校6*/ #include <bits/stdc++.h> using namespace std; int T, m; char str[2000 ...

  4. 2017 多校4 Wavel Sequence

    2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...

  5. 2017多校第3场 HDU 6058 Kanade's sum 双链表,思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6058 题外话:这场多校,真心感觉自己的无力,全队都发挥的很差,结束的时候排名掉到了90多,后期没做出字 ...

  6. HDU 6015 Colorful Tree(2017多校)

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6035 题意: 给出一颗树, 树上路径权值等于路径上不同颜色的数量,求所有路径权值之和: 解题思路: ...

  7. HDU 6044 Limited Permutation(2017多校)【计数 快速读入挂 线性逆元】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6044 题意: 对于有n个元素的全排列的合法性定义为:有n个区间,对于第i个区间[li,ri]有li& ...

  8. HDU 6134 2017 多校训练:Battlestation Operational(莫比乌斯反演+积性函数)

    实在太长了直接放题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6134 这题就是求 考虑当Gcd(i, j)==1时,除了j为1的情况,其它时候i/j一 ...

  9. 2017多校第4场 HDU 6078 Wavel Sequence DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6078 题意:求两个序列的公共波形子序列的个数. 解法: 类似于最长公共上升子序列,对于每个i,只考虑存 ...

最新文章

  1. matlab norm 范式
  2. 工作随笔-日常工作-小说站 PC版
  3. const char*, char const*, char*const 的区别
  4. HTML5 Web SQL数据库
  5. linux打包压缩命令有哪些,Linux压缩打包命令使用方法有哪些呢?
  6. MySql 你知道什么情况下适合使用Join 联表查询吗 ?
  7. 华为p50预计售价鸿蒙是什么,华为P50pro曝光,鸿蒙0S+5500毫安,售价却让人买不起...
  8. 万分之二用百分之怎么表示_农村建房时,“砖砌的化粪池”怎么做?听完内行人的分析,明白了...
  9. 高吞吐低延迟Java应用的垃圾回收优化
  10. 此页的状态信息无效,可能已损坏---应用程序中的服务器错误---
  11. Thymeleaf数据回显
  12. 一起学Vue自定义组件之拼图小游戏
  13. 【笔记】《算法竞赛 从入门到进阶(罗勇军)》第7章 动态规划
  14. linux deepin配置优化:解决deepin v20.5不能自动降频导致CPU风扇一直狂转吹热气的问题
  15. 使用uni-app把h5网页封装成app
  16. pc端点击按钮下载app
  17. 如何才能使自己看懂英文文献
  18. IDEA 卡住半天,buid(编译)不动——解决办法(适用于maven和gradle)及定位全过程...
  19. 使用 dcm4che 操作 Dicom 文件
  20. 如何用 Python 爬取网页制作电子书

热门文章

  1. sip-selvet 环境搭建
  2. SWT的UI线程和非UI线程
  3. 通用函数get和set
  4. 属性总结(四):linestyle
  5. 《机器学习实战》-线性回归
  6. SQL 创建存储过程,让主键自增
  7. jquery通过ajax向后台发送(checkbox)数组,并在后台接收,(发送的数据是checkedbox)...
  8. NOIP2009普及组细胞分裂(数论)——yhx
  9. 增加 addDataScheme(file) 才能收到SD卡插拔事件的原因分析 -- 浅析android事件过滤策略...
  10. 如何正确使用Windows的Ping命令