HDU 2588 GCD (欧拉函数)
Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem:
Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.
Input
Output
Sample Input
Sample Output
Source
#include <iostream>
#include <cmath>
using namespace std;
int enlur(int n) //求欧拉函数
{
int ans=n;
for(int i=;i*i<=n;i++)
{
if(n%i==)
{
ans=ans/i*(i-);
while(n%i==)
n/=i;
}
}
if(n>)
ans=ans/n*(n-);
return ans;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m,ans=;
cin>>n>>m;
int tmp=sqrt(n);
for(int i=;i<=tmp;i++)
{
if(n%i==)
{
if(i>=m)
ans+=enlur(n/i);
if(n/i>=m)
ans+=enlur(i);
}
}
if(tmp*tmp==n&&tmp>=m) //注意得是tmp>=n
ans-=enlur(tmp);
cout<<ans<<endl;
}
}
HDU 2588 GCD (欧拉函数)的更多相关文章
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1695 GCD 欧拉函数+容斥定理
输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和 ...
- HDU 1695 GCD (欧拉函数,容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- hdu 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 1695 GCD 欧拉函数 + 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1695 要求[L1, R1]和[L2, R2]中GCD是K的个数.那么只需要求[L1, R1 / K] 和 [L ...
- HDU 1695 GCD 欧拉函数+容斥原理+质因数分解
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:在[a,b]中的x,在[c,d]中的y,求x与y的最大公约数为k的组合有多少.(a=1, a ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- HDU 2824 简单欧拉函数
1.HDU 2824 The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...
- POJ 2773 Happy 2006【GCD/欧拉函数】
根据欧几里德算法,gcd(a,b)=gcd(a+b*t,b) 如果a和b互质,则a+b*t和b也互质,即与a互质的数对a取模具有周期性. 所以只要求出小于n且与n互质的元素即可. #include&l ...
随机推荐
- 一个项目中哪些文件是要上传到 git上的,哪些是不必要的
- Erlang第一课----基本变量
1.(in Erlang shell)A sequence of expressions must be terminated with a period followed by whitespace ...
- BurpSuite之SQL Injection
BurpSuite之SQL Injection[平台]:mutillidae[工具]BurpSuite 1.4.07 + FireFox1:安装配置mutillidae如果遇到问题,开下面的帖子.ht ...
- 平衡二叉树,AVL树之图解篇
学习过了二叉查找树,想必大家有遇到一个问题.例如,将一个数组{1,2,3,4}依次插入树的时候,形成了图1的情况.有建立树与没建立树对于数据的增删查改已经没有了任何帮助,反而增添了维护的成本.而只有建 ...
- Java统计数据库表中记录数
public static int count(String txyl_table) {// 获取用户数量 int i = 0;// Store_Information Connection con ...
- 三大框架ssh
一.hibernate a.实体类+映射 b.lib hibernate包+oracle包(oracle安装里找) 映射:从类入手class+属性 a.映射的头文件在:hibernate3.jar- ...
- PQ格式化虚拟机硬盘如何生效
用pq格式化虚拟机硬盘后,安装时,总是从dhcp的网卡启动,没有从硬盘启动 但是用ghost是可以拷贝镜像文件的 这就是说,硬盘有了,但是没有将硬盘"激活",没有将硬盘设为acti ...
- 微信内置浏览器的 User Agent的判断
如何判断微信内置浏览器,首先需要获取微信内置浏览器的User Agent,经过在 iPhone 上微信的浏览器的检测,它的 User Agent 是: Mozilla/5.0 (iPhone; CPU ...
- socket基本
fd_set用法: http://blog.sina.com.cn/s/blog_5c8d13830100erzs.htm socket连接: lpszHost="127.0.0.1&quo ...
- POJ 3349 Snowflake Snow Snowflakes
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...