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 ...
随机推荐
- Demo_玩家移动(主要注意动画的设置)
using UnityEngine; using System.Collections; public class NewPlayerMove : MonoBehaviour { private fl ...
- Linux Kernel: buffers和cached的区别
The page cache caches pages of files to optimize file I/O. The buffer cache caches disk blocks to op ...
- JNI之有必要的优化设计
对象指针的保存 在上一章中,c函数中将会获取的一些值,例如:FieldID.MethodID.jclass等数据.这些数据如果定义在函数内部,在函数返回时就会丢失.很多时候,在java与c的多次交互中 ...
- jquery之获取当前时间
/** * * 获取当前时间 */ function p(s) { return s < 10 ? '0' + s: s; } var myDate = new Date(); //获取当前年 ...
- 如何参与一个GitHub开源项目
Github作为开源项目的著名托管地,可谓无人不知,越来越多的个人和公司纷纷加入到Github的大家族里来,为开源尽一份绵薄之力.对于个人来讲,你把自己的项目托管到Github上并不表示你参与了Git ...
- 洛谷 P1273 有线电视网(dp)
/* 想了半天没想出状态 自己还是太弱了 QAQ 题目问的是最多供给多少户 一般想法是把这个值定义为状态量 没想出来QAQ....看了看题解的状态 很机智.... f[i][j]表示i的子树 选了j个 ...
- jquery.cookie用法详细解析
本篇文章主要是对jquery.cookie的用法进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 Cookie是由服务器端生成,发送给User-Agent(一般是浏览器),浏览器会将 ...
- Character Encoding tomcat.
default character encoding of the request or response body: If a character encoding is not specified ...
- spring中涉及事务(bean中ref与local)
<bean id="接口" parent="父id"> <property name="target"> <r ...
- Swift - 24 - switch语句的高级用法
//: Playground - noun: a place where people can play import UIKit // 对区间进行判断 var score = 90 switch s ...