题意:求出在一个区间[A,B]内与N互质的个数 。

思路:

先求出n的质因子,然后求出与N的质因子不互质的个数然后总个数减去就是。用位运算二进制表示那个因子用到过,实现容斥原理。在1到n之间是c倍数的个数为n/c;

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std; int t;
LL a,b,n;
LL f[];
int cnt; void inti()
{
memset(f,,sizeof(f));
cnt=;
for(int i=; i*i<=n; i++)
{
if(n%i==)
{
f[cnt++]=i;
while(n%i==)
{
n=n/i;
}
}
}
if(n>)
{
f[cnt++]=n;
}
} LL Get_num(LL m)
{
LL ans=;
for(int i=; i<(<<cnt); i++)
{
int xx=;
LL x=;
for(int j=; j<cnt; j++)
{
if(i&(<<j))
{
xx++;
x*=f[j];
}
}
if(xx%!=)
{
ans+=m/x;
}
else
{
ans-=m/x;
}
}
return m-ans;
} int main()
{
scanf("%d",&t);
for(int cas=; cas<=t; cas++)
{
scanf("%I64d%I64d%I64d",&a,&b,&n);
inti();
printf("Case #%d: %I64d\n",cas,Get_num(b)-Get_num(a-));
}
return ;
}

hdu Co-prime的更多相关文章

  1. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  2. HDU 1016 Prime Ring Problem(经典DFS+回溯)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. hdu 1973 Prime Path

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Description The ministers of the cabi ...

  4. HDU 1016 Prime Ring Problem

    在刚刚写完代码的时候才发现我以前交过这道题,可是没有过. 后来因为不理解代码,于是也就不了了之了. 可说呢,那时的我哪知道什么DFS深搜的东西啊,而且对递归的理解也很肤浅. 这道题应该算HDU 261 ...

  5. [HDU 1016]--Prime Ring Problem(回溯)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...

  6. [HDU 1973]--Prime Path(BFS,素数表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Time Limit: 5000/1000 MS (Java/Others ...

  7. HDU 1016 Prime Ring Problem 题解

    Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ... ...

  8. HDU 1016 Prime Ring Problem(素数环问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...

  9. hdu 1016 Prime Ring Problem(DFS)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  10. hdu 1016 Prime Ring Problem(深度优先搜索)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

随机推荐

  1. spring注解方式实现定时器,并且cron表达式中不识别L的方法

    1.Spring的配置: <beans xmlns:task="http://www.springframework.org/schema/task" xsi:schemaL ...

  2. Excel导入mysql数据库

    步骤一:选取要导入的数据快儿,另外要多出一列,如下图:    步骤二:  将选中的数据快儿拷贝到一个新建的表格工作薄,然后“另存为” ->“文本文件(制表符分割)(*.txt)”,假如存到“D: ...

  3. 学习restful 架构

    越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件"采用客户端/服务器模式,建立在分布式体系上,通过互联网通信,具有高延时(high latency).高 ...

  4. Android获取cpu和内存信息、网址的代码

      android获取手机cpu并判断是单核还是多核 /** * Gets the number of cores available in this device, across all proce ...

  5. [ArcGIS所需的补丁]ArcGIS 10.2.2 for Desktop联系Oracle(2014年10上个月发布)数据库崩溃

    环境的叙述性说明: ArcGIS 10.2.2 for Desktop.Oracle12.1.0.2 RAC 这仅仅是用户当时环境描写叙述.可是导致该问题的解决办法还包含很多其它的环境! 问题描写叙述 ...

  6. Redis配置文件分析

    #Redis演示示例配置文件 # 注意单位问题:当须要设置内存大小的时候,能够使用类似1k.5GB.4M这种常见格式: # # 1k=> 1000 bytes #1kb => 1024 b ...

  7. ListView嵌套ListView优化

    在做业务时候,一个ListView显示多种数据类型,我们想到的方法是ListView在嵌套一个ListView,对于子ListView 占父ListView的一行,就攻克了问题,可是这种逻辑是不是有点 ...

  8. android-个性化进度条

    1.案例效果图 2.准备素材                                progress1.png(78*78)              progress2.png(78*78) ...

  9. C# 汉字的字符串截取指定字节的长度

    int index = 0;            int setCharCount = 74;            string str1 = "三星 SCH-I829 电信3G手机(优 ...

  10. java中对象的转型

    1.对象的向上转型——将子类的对象赋值给父类的引用 Student s=new Student();  Person p=s; 一个引用能够调哪些成员(变量和函数),取决于这个引用的类型  也就是Pe ...