hdu Co-prime
题意:求出在一个区间[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的更多相关文章
- HDOJ(HDU).1016 Prime Ring Problem (DFS)
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDU 1016 Prime Ring Problem(经典DFS+回溯)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1973 Prime Path
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Description The ministers of the cabi ...
- HDU 1016 Prime Ring Problem
在刚刚写完代码的时候才发现我以前交过这道题,可是没有过. 后来因为不理解代码,于是也就不了了之了. 可说呢,那时的我哪知道什么DFS深搜的东西啊,而且对递归的理解也很肤浅. 这道题应该算HDU 261 ...
- [HDU 1016]--Prime Ring Problem(回溯)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- [HDU 1973]--Prime Path(BFS,素数表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Time Limit: 5000/1000 MS (Java/Others ...
- HDU 1016 Prime Ring Problem 题解
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ... ...
- HDU 1016 Prime Ring Problem(素数环问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- hdu 1016 Prime Ring Problem(DFS)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1016 Prime Ring Problem(深度优先搜索)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- 在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b
偶然在群里看到这个小题, 就用python做了做. 思路就是建一个够大的列表并初始化,把每个字符的asc码作为下标,存到列表里, 然后该位置的值就存字母的出现次数, 最后再迭代原字符串并判断列表值是否 ...
- 九度OnlineJudge之1001:A+B for Matrices
题目描述: This time, you are supposed to find A+B where A and B are two matrices, and then count the num ...
- [PWA] 4. Hijacking Request
We want to do offline first, the first thing we need to do is we should able to catch the browser re ...
- ASP.NET数据报表之柱状图 ------工作日志
#region 柱形色调 /// <summary> /// 柱形色调 /// </summary> private string[] myColor = new string ...
- GridView布局及适配器优化
1.布局样式 <GridView android:id="@+id/gridView" android:layout_width="fill_parent" ...
- tomcat - 部署Web应用
概述 以前,安装李刚的JavaEE里面说的方法部署应用的时候,无意中成功,但是后来每次要录视频的时候,又报错,思来想去,tomcat都重启了好多次了,配置文件也试过很多次了,还是不行.无意中发现了问题 ...
- Android Marquee
android:singleLine="true" android:marqueeRepeatLimit="marquee_forever" android:e ...
- 【转】 HVTableView创建--展开/折叠列表能 AAShareBubbles社会分享动画组
原文: http://blog.csdn.net/billfanggs/article/details/17279969 HVTableView HVTableView是UITableView(带有展 ...
- 第一章 Javascript基础
一.Javascript概述(知道) a.一种基于对象和事件驱动的脚本语言 b.作用: 给页面添加动态效果 c.历史: 原名叫做livescript.W3c组织开发的标准叫ECMAscipt. d.特 ...
- 【NOIP2014】赛后总结
noip考完了,心中所牵挂的一下子就消散了,感觉浑身很轻松. 说实话,我参加noip有好几次了,这应该会是我的最后一次,尽管如此,无论是在考试的前几天还是在考试的时候,心中都没有太多的紧张. 我在no ...