TrickGCD————(hdu6053)2017多校(莫比乌斯容斥)
来源:互联网 发布:拒绝退款后淘宝介入 编辑:程序博客网 时间:2024/06/04 18:50
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题意:给出一个数列,然后让你求出另一个数列有多少种可能;另一个数列满足数列gcd(b1,b2,……,bn)>=2而且对应的bi<=ai;解题思路:从2开始枚举到min(a1,a2……,an),然后计算含有这个因子的数出现的个数就是然后利用快速幂计算,然后会有重复计算,利用莫比乌斯容斥;#include <iostream>#include <cstring>#include <cstdio>using namespace std;typedef long long ll;ll mu[100005],cas=1;ll num[200005];int a[100005];ll mod=1e9+7;void mobius(ll mn){ mu[1]=1; for(ll i=1;i<=mn;i++){ for(ll j=i+i;j<=mn;j+=i){ mu[j]-=mu[i]; } }}ll Pow(ll x,ll n){ ll res=1; while(n>0) { if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res;}int main(){ int T,cas; scanf("%d",&T); cas=0; mobius(100000); while(T--) { cas++; int n; scanf("%d",&n); memset(num,0,sizeof(num)); int minn=100005; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); num[a[i]]++; minn=min(a[i],minn); } for(int i=1;i<=200000;i++) num[i]+=num[i-1]; ll sum=0; for(int i=2;i<=minn;i++) { ll su=1; for(int j=1;i*j<=100000;j++) { su=(su*Pow(j,num[i*(1+j)-1]-num[i*j-1]))%mod;//好好想一想在这里 } sum=(sum-(mu[i]*su)%mod+mod)%mod; } printf("Case #%d: %lld\n",cas,sum); } return 0;}
阅读全文
0 0
- TrickGCD————(hdu6053)2017多校(莫比乌斯容斥)
- 【HDU6053】TrickGCD(莫比乌斯容斥)
- 2017杭电多校联赛第二场-TrickGCD (hdu6053)莫比乌斯容斥
- 【2017多校】HDU6053 TrickGCD 【莫比乌斯】
- HDU6053 TrickGCD(2017多校第2场)
- [莫比乌斯反演] HDU6053: [2017 多校-第2场] TrickGCD
- hdu6053 TrickGCD 莫比乌斯反演
- [莫比乌斯函数][分段] hdu6053 TrickGCD (2017 Multi-University Training Contest
- HDU6053-TrickGCD 容斥原理+莫比乌斯反演
- hdu6053 TrickGCD 莫比乌斯函数 容斥原理
- HDU6053(莫比乌斯)
- HDU6053-TrickGCD
- hdu6053 TrickGCD
- HDU6053-TrickGCD
- HDU6053 TrickGCD
- TrickGCD hdu6053
- HDU 6053 TrickGCD (莫比乌斯函数)
- HDU 6053 TrickGCD(莫比乌斯函数)
- 【C++VS笔记】新装的VS2012 VS2013没有代码的智能提示功能的解决办法
- scala IDE for Eclipse开发Spark程序
- This is a new beginning
- android:ellipsize
- QT实现点击按钮出现信号
- TrickGCD————(hdu6053)2017多校(莫比乌斯容斥)
- Coursera机器学习笔记(week1)
- 查询数据库中字段不为空的数据
- 运行Spark提供的计算圆周率的示例程序
- Android主页动态添加Fragment
- LightOJ1214 Large Division
- HDU 5724 Chess (状压+sg)
- JQuery基本选择器
- CWorkBooks、CWorkBook、CWorkSheets、CWorkSheet、CRange简介