hdu4135Co-prime 容斥原理水题
//问一个区间[a,b]与n互素的数的个数
//利用容斥原理可知
//在[a,b] 区间内对n的素数因子
//ans = 被一个数整除的数的个数 - 被两个数的最小公倍数整除的数的个数 + 被三个数的。。。
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 100010 ;
typedef __int64 ll ;
ll p[maxn] ;int len ;
void get_prime(ll n)
{
len = 0 ;
for(ll i = 2;i*i <= n;i++)
{
if(n%i == 0)p[++len] = i ;
while(n%i == 0)n/=i ;
}
if(n>1)p[++len] = n;
}
ll dfs(int pos , ll n)
{
ll ans = 0 ;
for(int i = pos ;i <= len ;i++)
ans += n/p[i] - dfs(i+1 , n/p[i]) ;
return ans ;
}
int main()
{
ll a , b ,n ;
int T ;
int cas = 0 ;
scanf("%d" ,&T) ;
while(T--)
{
scanf("%I64d%I64d%I64d" , &a , &b , &n);
get_prime(n) ;
ll ans = (b - dfs(1 , b)) - (a - 1 - dfs(1 , a-1)) ;
printf("Case #%d: " ,++cas) ;
printf("%I64d\n" , ans) ;
}
return 0 ;
}
hdu4135Co-prime 容斥原理水题的更多相关文章
- UESTC--1272--Final Pan's prime numbers(水题)
Final Pan's prime numbers Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & % ...
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...
- UVa 1644 Prime Gap (水题,暴力)
题意:给定一个数 n,求它后一个素数和前一个素数差. 析:先打表,再二分查找. 代码如下: #pragma comment(linker, "/STACK:1024000000,102400 ...
- POJ2485Highways(prime 水题)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26516 Accepted: 12136 Descri ...
- 【UVA - 1644 / POJ - 3518】Prime Gap(水题)
Prime Gap 这里直接写中文了 Descriptions: 对于一个数n,若n为素数则输出0,否则找到距离n最小的两个素数,一个大于n,一个小于n,输出他们的差(正数) Input 多组输入 每 ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)
算法训练 Torry的困惑(基本型) 时间限制:1.0s 内存限制:512.0MB 问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...
- HDU 4813 Hard Code 水题
Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- LOJ #6303. 水题 (约数 质因数)
#6303. 水题 内存限制 10 MiB 时间限制:1000 ms 标准输入输出 题目描述 给定正整数 n,kn, kn,k,已知非负整数 xxx 满足 n!modkx=0,求 xmaxx_{max ...
随机推荐
- LeeCode-Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- sroHOBOorz来自HOBO的高精类
/* bigint() bigint(long long) bigint(bigint) bigint(char*) bigint(string) +, +=, ++ -, -=, -- *, *= ...
- Jekins安装
1. Jekins支持多系统:windows, mac,linux 2. Jekins安装方式有三种:直接war文件安装,安装包安装,将war文件放到web容器安装 3. 在windows下安装 a. ...
- IOS 掉用系统发短信
#import <MessageUI/MessageUI.h> MFMessageComposeViewControllerDelegate #pragma mark - 调用ios系统短 ...
- oracle Recyclebin
每个用户都有自己的Recycle Bin.删除的对象不会永久存储在Recycle Bin中,Oracle会按照一定的规则自动清除里面的内容,如没有足够的空间.执行show recyclebin时只列出 ...
- 更改yum网易 阿里云的yum源。
一,鉴于用国外的Yum源,速度比较慢,所以想到将国外的yum源,改为国内的Yum源,著名的有网易 阿里云源.如何更改呢? 二,更改yum源为网易的. 首先备份/etc/yum.repos.d/Cent ...
- ECSHOP首页站内快讯在哪里添加和修改?
“添加新闻后在首页站内快讯处显示不出来?”.“请问首页中站内快讯(最新文章)在后台哪个位置管理”.“如何让发布的文章进入首页站内快讯”等等诸如此类的问题,经常在论坛里看到一些朋友在询问. 本ECSHO ...
- 正式软件工作第一天————MVC、ext JS、和clsa
正式上班第一天,引导人就提出了MVC.extjs和clsa 三种框架,在这之前只听说了MVC,但还木有学习过,顺便把学习过程记录下来. MVC——初学习 1.M——model 模型:应用对象,处理业务 ...
- 在美国公司架构中,LLC、LLP 和 Corporation 的区别何在?
这个问题,首先需要弄清楚这样一个事实:LLC.LLP.Corporation分别属于三种不同类型的公司实体. 1,LLC (Limited Liability Company)是责任有限公司: 2,L ...
- mono for android 学习资料
http://www.cnblogs.com/Hua-Min/tag/Android/