hdu2588 GCD
GCD
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3559 Accepted Submission(s): 1921
(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.
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll; ll euler(ll x)
{
ll res = x;
for(int i= ;i*i<=x ;i++)
{
if(x%i == )
{
res = res/i*(i-);
while(x%i==)
x/=i;
}
}
if(x>)
res = res/x*(x-);
return res;
} int main(){
int T;
scanf("%d",&T);
while(T--)
{
ll n,m;
scanf("%I64d%I64d",&n,&m);
ll ans = ;
for(ll i= ;i*i<=n ;i++)
{
if(n%i == )//i是n的因数
{
if(i >= m)
{
ans += euler(n/i);
}
if((n/i)>=m && n/i != i)//i*(n/i)==n,判断i对应的另一个因数是否符合
{
ans += euler(i);
}
}
}
printf("%I64d\n",ans);
}
return ;
}
hdu2588 GCD的更多相关文章
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
- HDU2588 GCD(欧拉函数)
题目问[1,n]中与n的gcd大于等于m的数的个数. 好难想... 假设x满足条件,那么gcd(x,n)=d>=m,而x/d与n/d一定互质. 又x<=n,所以x/d<=n/d. 于 ...
- hdu2588 gcd 欧拉函数
GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU2588:GCD(欧拉函数的应用)
题目链接:传送门 题目需求:Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.(2& ...
- 从HDU2588:GCD 到 HDU5514:Frogs (欧拉公式)
The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the ...
- hdu2588 GCD 给定n,m。求x属于[1,n]。有多少个x满足gcd(x,n)>=m; 容斥或者欧拉函数
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Sub ...
- 【hdu-2588】GCD(容斥定理+欧拉函数+GCD()原理)
GCD Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- GCD hdu2588
GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用
OC中的三种定时器:CADisplayLink.NSTimer.GCD 我们先来看看CADiskplayLink, 点进头文件里面看看, 用注释来说明下 @interface CADisplayLin ...
随机推荐
- coordinatewise 是什么意思?
As far as I remember, in the context of optimization, "coordinate wise" means that you are ...
- SQL语句学习积累·数据的操作
数据的操作 select 取表中前五条数据 select top 5 from table_name 取表中前50%的数据 select top 50 percent from table_name ...
- HTTP协议相关介绍
一.HTTP请求方法 根据HTTP标准,HTTP请求可以使用多种请求方法.HTTP1.0定义了三种请求方法: GET, POST 和 HEAD方法.HTTP1.1新增了五种请求方法:OPTIONS, ...
- VC解决方案,项目,开发一段时间启动调试很慢,半天才开始链接
笔者这两天写代码过程中,发现自己解决方案下的程序启动调试,半天才开始加载相关的各种库.导致调试的时候很是郁闷 开始以为是项目关联的工程太多导致,但是在相同的解决方案sln下面,新建一个简单的控制台程序 ...
- Java 扫描器类 Scanner类
1.Scanner是SDK1.5新增的一个类,可是使用该类创建一个对象.Scanner reader=new Scanner(System.in); 2.reader对象调用下列方法(函数),读取用户 ...
- CSS概念 - 可视化格式模型(二) 定位概述(普通流、绝对定位)
2.定位概念 上一节熟悉了盒模型, 现在来看一下可视化格式模型和定位模型. 理解这两个模型的细微差异是非常重要的, 因为它们一起控制着如何在页面上布置每个元素 2.1 可视化格式模型 CSS有三种基本 ...
- create-react-app设置proxy反向代理不起作用
在CRA2.X升级以后对proxy的设置做了修改,引用官方升级文档: Object proxy configuration is superseded by src/setupProxy.js To ...
- Xcode更新至IOS 9 后错误处理
1.obtain an updated library from the vendor, or disable bitcode for this target. for architecture ar ...
- C#设计模式系列:适配器模式(Adapter Pattern)
一.引言 在软件系统中,由于应用环境的变化,常常需要将“一些现存的对象”放在新的环境中应用.但是新环境要求的接口是这些现存对象所不满足的.如何应对这种“迁移的变化”?如何既能利用现有对象的良好实现,同 ...
- Linux下启动Tomcat项目
在Linux下启动Tomcat项目方法:将war包放进Tomcat的wabapp目录下,进入tomcat目中的bin目录中,运行命令./startup.sh 回车就可以了