HDU 6053 TrickGCD 数论
来源:互联网 发布:乔丹新秀赛季数据 编辑:程序博客网 时间:2024/05/29 18:01
TrickGCD
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2532 Accepted Submission(s): 965
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
题意:问能构造多少序列 满足1<=bi<=ai且gcd(ai)>=2
题解:莫比乌斯搞一搞
for i
i代表当前gcd是i的倍数
然后用莫比乌斯容斥一下
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const ll mod=1000000007;ll quick(ll a,ll k){ ll ans=1; while(k){ if(k&1)ans=ans*a%mod; k/=2; a=a*a%mod; } return ans;}int mu[100005],cas=0;void mobius(int mn){ mu[1]=1; for(int i=1;i<=mn;i++){ for(int j=i+i;j<=mn;j+=i){ mu[j] -= mu[i]; } }}ll a[200005],cnt[200005];int main(){ int t,cas=1; mobius(100000); scanf("%d",&t); while(t--){ ll n,m,i,j; ll mis=999999; scanf("%lld",&n); memset(cnt,0,sizeof(cnt)); memset(a,0,sizeof(a)); for(i=1;i<=n;i++){ ll x; scanf("%lld",&x); a[x]++; mis=min(x,mis); } for(i=1;i<=200000;i++){ cnt[i]=cnt[i-1]+a[i]; } ll ans=0; for(i=2;i<=mis;i++){ ll temp=1; for(j=1;i*j<=100000;j++){ temp=(temp*quick(j,cnt[i*j+i-1]-cnt[i*j-1])%mod); } ans=(ans-temp*mu[i]+mod)%mod; } printf("Case #%d: %lld\n",cas++,(ans%mod+mod)%mod); } return 0;}
阅读全文
0 0
- HDU 6053 TrickGCD 数论
- 【数论-莫比乌斯】hdu 6053 TrickGCD
- HDU 6053 TrickGCD
- HDU 6053 TrickGCD
- HDU-6053 TrickGCD
- hdu 6053 TrickGCD
- HDU 6053 TrickGCD
- [HDU]6053 TrickGCD
- hdu--6053--TrickGCD
- hdu-6053TrickGCD
- HDU 6053 TrickGCD
- HDU 6053 TrickGCD
- 【 hdu 6053】 TrickGCD 【数论 容斥 + 莫比乌斯函数 】
- HDU 6053 TrickGCD DP(筛法)
- HDU 6053 TrickGCD(枚举)
- TrickGCD HDU
- TrickGCD HDU
- [数论 反演] HDU6053. TrickGCD
- Ubuntu安装、切换openjdk8
- String s1==s2面试题
- 关于字符类别的一些设计,含ASCLL码值
- Struts Problem Report Struts has detected an unhandled exception: Messages: node to traverse cann
- windows注册表,关联文件
- HDU 6053 TrickGCD 数论
- Trilateration三边测量定位算法
- linux下如何通过rabbitmq进行简单的电脑间通信
- 1096. Consecutive Factors (20)
- HDU 6050 Funny Function
- 图像处理20:自适应阈值
- android sdk环境变量配置
- 使用MyBatis Generator自动创建代码(最简单方法)
- 工作三年小结----我依然是那个不变初心的少年