D - GCD

HDU - 1695

  • 思路: 都 除以 k 后转化为  1-b/k    1-d/k中找互质的对数,但是需要去重一下  (x,y)  (y,x) 这种情况。
  • 这种情况出现 x  ,y 肯定 都在 min  (b/k, d/k)  ,所以 奇数 最后 减去 一半 即可。
  • #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define maxn 1234567
    bool vis[maxn+10];
    ll t,n,m,prime[maxn+10];
    ll mu[maxn+10],ans,a,b,c,d,k,sum;
    void getphi()
    {
    int cnt=0;
    mu[1]=1;
    for(int i=2; i<maxn; i++)
    {
    if(!vis[i])
    {
    prime[++cnt]=i;
    mu[i]=-1;
    }
    for(int j=1; j<=cnt&&i*prime[j]<maxn; j++)
    {
    vis[i*prime[j]]=1;
    if(i%prime[j]==0)
    {
    mu[i*prime[j]]=0;
    break;
    }
    else mu[i*prime[j]]=-mu[i];
    }
    }
    }
    int main()
    {
    getphi();
    scanf("%lld",&t);
    for(int q=1; q<=t; q++)
    {
    ans=sum=0;
    scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&k);
    if(k==0)
    {
    printf("Case %d: 0\n",q);
    continue;
    }
    b/=k,d/=k;
    n=min(b,d);
    for(int i=1; i<=n; i++)
    {
    ans+=(ll)mu[i]*(b/i)*(d/i);
    sum+=(ll)mu[i]*(n/i)*(n/i);
    }
    printf("Case %d: %lld\n",q,ans-sum/2);
    }
    return 0;
    }

      

D - GCD HDU - 1695 -模板-莫比乌斯容斥的更多相关文章

  1. CF(439E - Devu and Birthday Celebration)莫比乌斯容斥

    题意:将n个糖果插入f-1个挡板分成f分(a1,a2,a3...af). 问有多少种分法能够使得gcd(a1,a2,a3...af)=1; 解法.莫比乌斯容斥,首先按1为单位分,这时候有C(n-1,f ...

  2. [中山市选2011][bzoj2440] 完全平方数 [二分+莫比乌斯容斥]

    题面 传送门 思路 新姿势get 莫比乌斯容斥 $\sum_{i=1}{n}\mu(i)f(i)$ 这个东西可以把所有没有平方质因子的东西表示出来,还能容斥掉重复的项 证明是根据莫比乌斯函数的定义,显 ...

  3. GCD HDU - 1695 (欧拉 + 容斥)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. HihoCoder - 1867: GCD (莫比乌斯容斥)

    Sample Input 6 1 6 2 5 3 4 Sample Output 10 You are given a {1, 2, ..., n}-permutation a[1], a[2], . ...

  5. 2017ACM暑期多校联合训练 - Team 2 1009 HDU 60563 TrickGCD (容斥公式)

    题目链接 Problem Description You are given an array A , and Zhu wants to know there are how many differe ...

  6. CodeForces - 803F: Coprime Subsequences(莫比乌斯&容斥)

    Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common div ...

  7. hdu6053(莫比乌斯+容斥+分块)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意: 给出一个含 n 个元素的 a 数组, 求 bi <= ai 且 gcd(b1, ...

  8. HDU 4609 3-idiots FFT+容斥

    一点吐槽:我看网上很多分析,都是在分析这个题的时候,讲了半天的FFT,其实我感觉更多的把FFT当工具用就好了 分析:这个题如果数据小,统计两个相加为 x 的个数这一步骤(这个步骤其实就是求卷积啊),完 ...

  9. HDU 5297 Y sequence 容斥 迭代

    Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integer ...

随机推荐

  1. json字符串和字典的区别补充

    json字符串和字典的区别:json:(JavaScript Object Notation)的首字母缩写,字面的意思是(javascript对象表示法),这里说的json指的是类似于javascri ...

  2. 第十八单元 nginx服务

    安装python 源 wget   网上下载 原码 编译    安装的流程 (gcc glic) 版本更新时起冲突,删除原版本(或者reinstall重新安装) 可执行文件运行   ./ 软连接 查看 ...

  3. XSS-HTML&javaSkcript&CSS&jQuery&ajax

    1.设置不同的样式列表 <style> ul.a{list-style-tyrp:circle;}    ul.b{list-style-type:square;}   ul.c{list ...

  4. A^B Mod C

    A^B Mod C 时间限制: 1 Sec  内存限制: 32 MB Problem Description 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = ...

  5. rsync启动并生成PID

    /usr/bin/rsync --daemon --config=/usr/local/rsync/etc/rsyncd.conf

  6. IDEA的字体设置

    最后点击ok

  7. 在Ubuntu下创建一个新的用户

    Step1:添加新用户useradd -r -m -s /bin/bash 用户名 Step2:配置新用户密码passwd 用户名 Step3:给新添加的用户增加ROOT权限vim /etc/sudo ...

  8. Unable to locate package python-pip

    原文:https://blog.csdn.net/yyinhai/article/details/53056973 Ubuntu下执行apt install python-pip得到如下错误提示: R ...

  9. SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问

    SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问 https://blog.csdn.net/yft_android/article/details/80307672

  10. mongodb实现自增的方法

    前面操作看菜鸟教程 function getNextSequenceValue(sequenceName){ var sequenceDocument = Counter.findOneAndUpda ...