莫比乌斯函数 hdu6053
来源:互联网 发布:淘宝人工客服电话 编辑:程序博客网 时间:2024/05/20 01:37
TrickGCD
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2997 Accepted Submission(s): 1121
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
#include<bits/stdc++.h>using namespace std;#define N 200011const int mod=1e9+7;typedef long long LL;int mu[110000];int MAXN=100000;int a[110000];int num[210000];void Moblus(){ mu[1]=1; for(int i=1; i<=MAXN; i++) for(int j=i+i; j<=MAXN; j+=i) mu[j]-=mu[i];}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(){ Moblus(); int t; scanf("%d",&t); for(int k=1; k<=t; k++) { int i,j,n; scanf("%d",&n); memset(a,0,sizeof(a)); int mn=100005; int mx=-1; for(i=0; i<n; i++) { int x; scanf("%d",&x); mn=min(x,mn); mx=max(x,mx); a[x]++; } num[0]=a[0]; for(i=1; i<=100100; i++) num[i]=num[i-1]+a[i]; LL sum=0; int l,r; for(i=2; i<=mn; i++) { LL ans=1; for(j=1; j*i<=mx; j++) { r=(j+1)*i-1; l=j*i-1; if(r>100000) r=100000; ans=(ans*qpow(j,num[r]-num[l]))%mod; } sum=(sum-ans*mu[i]%mod+mod)%mod; } printf("Case #%d: %lld\n",k,sum); } return 0;}
阅读全文
0 0
- hdu6053 莫比乌斯函数
- 莫比乌斯函数 hdu6053
- HDU6053(莫比乌斯函数+容斥定理)
- hdu6053 TrickGCD 莫比乌斯函数 容斥原理
- hdu6053-容斥+莫比乌斯函数+优化
- HDU6053(莫比乌斯)
- hdu6053 TrickGCD 莫比乌斯反演
- hdu6053-莫比乌斯反演
- 【数论】莫比乌斯反演证明+HDU6053(莫比乌斯函数)
- [莫比乌斯函数][分段] hdu6053 TrickGCD (2017 Multi-University Training Contest
- hdu6053 多校第二场(莫比乌斯函数,枚举)
- HDU6053-TrickGCD 容斥原理+莫比乌斯反演
- 【2017多校】HDU6053 TrickGCD 【莫比乌斯】
- 【HDU6053】TrickGCD(莫比乌斯容斥)
- [莫比乌斯反演] HDU6053: [2017 多校-第2场] TrickGCD
- 莫比乌斯函数
- 莫比乌斯函数
- 莫比乌斯函数
- libreoj 6000. 「网络流 24 题」搭配飞行员
- 个人总结一个合格的SEOer需要有怎么样的心态?
- 关于Jmeter打开.jmx文件报错的解决办法
- 详细解读神经网络十大误解,再也不会弄错它的工作原理
- ireport、jasperreport 导出excel的java代码
- 莫比乌斯函数 hdu6053
- 3A算法 AF AE AWB
- JZOJ5259. 线性规划问题
- mysql学习-----锁概念
- nginx(地址重写)
- mysql 索引详解
- ZOJ
- centos7安装zabbix-agent
- 【真题】拼多多2018校招内推编程题 最大乘积