HDU4135容斥原理
#include <cstdio>
#include <string.h>
#include <cmath> using namespace std; #define MAXSIZE 40000
#define LL long long
int prim[MAXSIZE];
LL A,B,n,odd,even;
int k;//k记录素数的个数 void findPrim(LL n)
{
k=;
for(int i=; i*i<=n; i++) //对n进行素因子分解
{//筛法求素数
if(n%i==)
{
prim[k++]=i;
while(n%i==)
n/=i;
}
}
if(n>)
prim[k++]=n;
} void getCount(int N)
{
long long mul=;
int count=;
int m=;
while(N){
if(N&) {
count++;
mul*=prim[m];
}
m++;
N>>=;
}
long long t=B/mul-(A-)/mul;
if(count%==) even+=t;
else odd+=t;
} int main()
{
int T,log;
scanf("%d",&T);
for(int x=;x<=T;x++)
{
odd=,even=,log=;
scanf("%I64d%I64d%I64d",&A,&B,&n);
findPrim(n); /*for(int i=0;i<k;i++) printf("%d ",prim[i]);
printf("\n");*/ while(log<(<<k)){
getCount(log);
log++;
}
printf("Case #%d: ",x);
printf("%I64d\n",B-A+-odd+even);
}
return ;
}
HDU4135容斥原理的更多相关文章
- hdu4135容斥原理 组合遍历
容斥原理实现的关键在于:组合遍历,即如何遍历2^n种组合. 容斥原理的三种写法: DFS 队列数组 位数组 #include<stdio.h> #include<iostream&g ...
- HDU4135(容斥原理)
Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU4135 Co-prime(容斥原理)
题目求[A,B]区间内与N互质数的个数. 可以通过求出区间内与N互质数的个数的前缀和,即[1,X],来得出[A,B]. 那么现在问题是求出[1,X]区间内与N互质数的个数,考虑这个问题的逆问题:[1, ...
- hdu4135 Co-prime 容斥原理
Given a number N, you are asked to count the number of integers between A and B inclusive which are ...
- 容斥原理的(二进制思想和质因子分解+模板)hdu4135+ecf81.D
题:http://acm.hdu.edu.cn/showproblem.php?pid=4135 题意:求[A,B]与N互质的数的个数 #include<iostream> #includ ...
- hdu4135 Co-prime【容斥原理】
Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...
- 容斥原理应用(求1~r中有多少个数与n互素)
问题:求1~r中有多少个数与n互素. 对于这个问题由容斥原理,我们有3种写法,其实效率差不多.分别是:dfs,队列数组,位运算. 先说说位运算吧: 用二进制1,0来表示第几个素因子是否被用到,如m=3 ...
- hdu4059 The Boss on Mars(差分+容斥原理)
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 1. ...
随机推荐
- jquery 选择器包含特殊字符
选择器包含 : .# ( ] 等等 比如 <div id="id#a"></div> <div id="id[1]">< ...
- 2. UITest相关APIs
1. XCUIApplication 这是你正在测试的应用的代理.它能让你启动应用,这样你就能执行测试了.它每次都会新起一个进程,这会多花一些时间,但是能保证测试应用时的状态是干净的,这样你需要处理的 ...
- 洛谷2017 5月月赛R1
我只想说面对这种难度的题目就是冲着20%的数据暴力... 分数:40+20+36.1+38+0+19 T1 签到题 III 题目背景 pj组选手zzq近日学会了求最大公约数的辗转相除法. 题目描述 类 ...
- Angularjs 实现 $(document).ready()的两种方法
1.在controller里面利用$on或者$watch bookControllers.controller('bookctrl_test', ['$scope', '$routeParams', ...
- Android中单选框RadioButton的基本用法
总结一下设置图标的三种方式: (1)button属性:主要用于图标大小要求不高,间隔要求也不高的场合. (2)background属性:主要用于能够以较大空间显示图标的场合. (3)drawableL ...
- Node + Express + MySQL 接口开发完整案例
https://blog.csdn.net/u013216976/article/details/85273770 https://github.com/Apache-Ra/node-express- ...
- OpenCV2:第七章 图像处理
一.简介 灰度图(灰阶图),把白色到黑色之间分为256阶灰度 彩色图有RGB三个分量,假设图是800*800像素,那么就有三个800*800的矩阵分别代表RGB 二值化处理设定阈值,在阈值中的像素值变 ...
- vue 父子组件的加载顺序
一.加载渲染过程 父beforeCreate->父created->父beforeMount->子beforeCreate->子created->子beforeMount ...
- 天梯赛L1 题解
L1-001 Hello World (5 分) 这道超级简单的题目没有任何输入. 你只需要在一行中输出著名短句“Hello World!”就可以了. AC代码:(直接输出记性) #include & ...
- excel组装sql
="INSERT INTO TABLE_XXXX (COLUMN_1, COLUMN_2, COLUMN_3, COLUMN_4, COLUMN_5, COLUMN_6, COLUMN_7, ...