思路:直接用求(b,1)范围内互质的数,(a-1,1)范围内互质的数。再求反

就是敲一下容斥模板

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
#define LL long long
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// } int T;
LL a,b,n;
int pri[];
int k;
void fun(LL x){
k=;
for(int i=;i*i<=x;i++){
if(x&&x%i==){
pri[k++]=i;
while(x&&x%i==){
x/=i;
}
}
}
if(x>) pri[k++]=x;
}
LL exclu(LL num,int m){
LL ans=,tmp,times;
for(int i=;i<(LL)(<<m);i++){
tmp=,times=;
for(int j=;j<m;j++){
if(i&((LL)(<<j)))
times++,tmp*=pri[j];
}
if(times&) ans+=num/tmp;
else ans-=num/tmp;
}
return ans;
}
int main(){
scanf("%d",&T); int cas=;
while(T--){
scanf("%I64d%I64d%I64d",&a,&b,&n);
clc(pri,);
fun(n);
LL ans1=exclu(a-,k);
LL ans2=exclu(b,k);
printf("Case #%d: %I64d\n",cas++,b-ans2-(a--ans1));
}
return ;
}

HDU 4135 Co-prime的更多相关文章

  1. HDU 4135 容斥

    问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...

  2. [容斥原理] hdu 4135 Co-prime

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4135 Co-prime Time Limit: 2000/1000 MS (Java/Others) ...

  3. hdu 5901 count prime & code vs 3223 素数密度

    hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...

  4. HDU 4135

    http://acm.hdu.edu.cn/showproblem.php?pid=4135 求[A,B]内与N互素的数字个数 首先对N分解质因数,对于一个质因数,1-n与它不互素的数字个数是n/(这 ...

  5. hdu 4135 a到b的范围中多少数与n互质(容斥)

    Co-prime 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4135 input The first line on input contains ...

  6. hdu (kruska and prime) 继续畅通工程

    题目http://acm.hdu.edu.cn/showproblem.php?pid=1879 复习一下最小生成树的两个基本算法. 由于存在道路是否已修建的问题,如果已修建,那么该条道路的成本即为0 ...

  7. hdu 4135 [a,b]中n互质数个数+容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=4135 给定一个数n,求某个区间[a,b]内有多少数与这个数互质. 对于一个给定的区间,我们如果能够求出这个区间内 ...

  8. 容斥 - HDU 4135 Co-prime

    Co-prime Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=4135 推荐: 容斥原理 Mean: 给你一个区间[l,r]和一 ...

  9. 【容斥】HDU 4135 Co-prime

    acm.hdu.edu.cn/showproblem.php?pid=4135 [题意] 询问[a,b]中与n互质的数有多少个 [思路] 考虑[1,m]中与n互质的数有多少个,答案就是query(b) ...

  10. 【hdu 4135】Co-prime

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=4135 [题意] 让你求出[a..b]这个区间内和N互质的数的个数; [题解] 利用前缀和,求出[1 ...

随机推荐

  1. windows下使用MinGW的调试工具gdb.exe调试C程序

    1.编译源代码 C:MinGW\bin>gcc.exe -g -o program.exe program.c 编译选项上要加上“g”,这样生成的目标程序会含有调试内容,再用gdb调试的时候才能 ...

  2. sencha touch jsonp

    asp.net server side code <%@ Page Language="C#" %> <script runat="server&quo ...

  3. Portlet 通信过程详解

    Portlet 通信过程详解 在 Portal 的开发过程中,Theme 与 portlet 之间的通信,以及 portlet 之间的通信是开发人员常常遇到的问题.通常 Portlet 之间需要能够互 ...

  4. [DP] Rod-cutting problem

    给一个长度为 n 的杆子,切成小段卖出去,价格根据小段的长度不同而不同.下面是一个例子 我们要通过切成小段卖出尽可能高的总价钱.问题是:How to decompose the problem? De ...

  5. Weex详解:灵活的移动端高性能动态化方案

    原文地址:http://www.infoq.com/cn/articles/introducing-weex 在2016年4月份的QCon上,阿里巴巴资深总监,淘宝移动平台及新业务事业部.阿里百川负责 ...

  6. POJ 3007 Organize Your Train part II(哈希链地址法)

    http://poj.org/problem?id=3007 题意 :给你一个字符串,让你无论从什么地方分割,把这个字符串分成两部分s1和s2,然后再求出s3和s4,让你进行组合,看能出来多少种不同的 ...

  7. Mysql 批量建表存储过程

    最近项目中用到了使用存储过程批量建表的功能,记录下来: USE db_test_3; drop procedure if EXISTS `createTablesWithIndex`; create ...

  8. 怎么修改tomcat默认访问首页

    一般情况下安装好tomcat之后我们的默认访问首页是index了,但我们如果要修改或增加一个默认首页,我们可参考下面办法来解决. 通过 ip:port 访问到的是 tomcat 的管理页面,其他常规部 ...

  9. 屏幕尺寸,屏幕分辨率,屏幕密度,各种长宽单位(px,sp,dp,in.pt,mm)

    常见长宽单位表 名称 单位缩写 单位全拼 介绍 屏幕尺寸 '' 或 in inch 屏幕的大小,通常用屏幕对角线的长度表示.单位是寸 屏幕分辨率 px pixels 整个屏幕的像素数,一般用屏幕的像素 ...

  10. Drawable(2)State list Drawable Resource介绍

    State List A StateListDrawable is a drawable object defined in XML that uses a several different ima ...