博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4135 Co-prime(容斥+数论)
阅读量:6250 次
发布时间:2019-06-22

本文共 1799 字,大约阅读时间需要 5 分钟。

Co-prime

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5526    Accepted Submission(s): 2209

Problem Description
Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.
Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than 1 or, equivalently, if their greatest common divisor is 1. The number 1 is relatively prime to every integer.
 

 

Input
The first line on input contains T (0 < T <= 100) the number of test cases, each of the next T lines contains three integers A, B, N where (1 <= A <= B <= 10
15) and (1 <=N <= 10
9).
 

 

Output
For each test case, print the number of integers between A and B inclusive which are relatively prime to N. Follow the output format below.
 

 

Sample Input
2 1 10 2 3 15 5
 

 

Sample Output
Case #1: 5 Case #2: 10
Hint
In the first test case, the five integers in range [1,10] which are relatively prime to 2 are {1,3,5,7,9}.
 

 

Source

 

/** @Author: lyuc* @Date:   2017-08-16 16:52:21* @Last Modified by:   lyuc* @Last Modified time: 2017-08-16 21:44:34*//* 题意:给你a,b,n让你求在区间[a,b]内有多少数与n互质 思路:求出n的所有质因子,然后[1,a]区间内的与n互质的数的数量就是,a减去不互质的数的数量,同理     [1,b]的也可以这么求,容斥求出这部分的结果*/#include 
#define LL long long#define MAXN 1005#define MAXM 10005using namespace std;int t;LL a,b,n;LL factor[MAXN];LL tol;LL que[MAXM];void div(LL n){
//筛出来n的因子 tol=0; for(LL i=2;i*i<=n;i++){ if(n%i==0){ factor[tol++]=i; while(n%i==0){ n/=i; } } } if(n!=1) factor[tol++]=n;//如果是素数的话加上本身}LL cal(LL x){
//容斥计算出[1,x]内与n不互质的元素的个数 LL res=0; LL t=0; que[t++]=-1; for(int i=0;i

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/7376139.html

你可能感兴趣的文章
DoTA与人生
查看>>
〖Android〗/system/etc/media_codecs.xml
查看>>
ESN 与 MEID
查看>>
MySQL server version for the right syntax to use near ‘USING BTREE
查看>>
launch failed.Binary not found
查看>>
MySql服务器的启动和关闭
查看>>
Android访问远程网页取回json数据
查看>>
Android之等比例显示图片
查看>>
HTML5 data-* 自定义属性
查看>>
linux系统装windows时需要注意的问题
查看>>
android textview 行间距
查看>>
HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
查看>>
[JS5] 利用onload执行脚本
查看>>
剑指OFFER之矩形覆盖(九度OJ1390)
查看>>
Scrum 学习笔记
查看>>
Ext.form.ComboBox常用属性详解
查看>>
HTTP Header 详解
查看>>
Java中的HashMap 浅析
查看>>
调和映射的Bochner公式
查看>>
windows批处理
查看>>