HDU2588
结论:如果p是n的约数,那么满足gcd(i,n)==p的i的个数是Φ(n/p)
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+11;
typedef long long ll;
ll euler(int n){
ll ans=n;
for(ll i = 2; i*i <= n; i++){
if(n%i==0){
ans=ans/i*(i-1);
while(n%i==0) n/=i;
}
}
if(n>1) ans=ans/n*(n-1);//note
return ans;
}
int main(){
int T; scanf("%d",&T);
while(T--){
int n,m; ll ans=0;
scanf("%d%d",&n,&m);
for(ll i = 1; i*i<=n; i++){
if(n%i==0){
if(i>=m) ans+=euler(n/i);
if(n/i>=m&&i*i!=n) ans+=euler(i);
}
}
printf("%lld\n",ans);
}
}
HDU2588的更多相关文章
- 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 ...
- 【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 ...
- 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
GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 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 ...
随机推荐
- 面试题:hibernate 有用
1. Hibernate的工作流程? 答案: 1.通过Configuration对象读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory对象 3.打开session 4.创建事 ...
- blockchain notes
1. IBM blockchain platform https://www.ibm.com/blockchain/platform/ 2. 开源项目hyperledger https://hyper ...
- 30.MIN() 函数
MIN() 函数 MIN 函数返回一列中的最小值.NULL 值不包括在计算中. SQL MIN() 语法 SELECT MIN(column_name) FROM table_name 注释:MIN ...
- Smarty3——从配置文件获取的变量
再使用配置变量前要 引入配置变量即:{$config_load file=‘file_path’}$marty3中可以从配置文件中 用 # 号包起来引用配置文件中的变量({#config_var_na ...
- IntelliJ IDEA——maven环境下整合SSM
SSM整合目录结构 开发环境:JDK1.8:apache-tomcat-7.0.52 : MySql5.7 开发工具:IntelliJ IDEA pom.xml <?xml version=&q ...
- [GO]将随机生成的四位数字拆分后放到一个切片里
package main import ( "math/rand" "time" "fmt" ) func InitData(p *int) ...
- Linux网络编程IPv4和IPv6的inet_addr、inet_aton、inet_pton等函数小结(转)
原文:http://blog.csdn.net/ithomer/article/details/6100734 知识背景: 210.25.132.181属于IP地址的ASCII表示法,也就是字符串形式 ...
- Sort函数(C++)
原创 C++中内置了sor函数供排序,函数原型为: #include<algorithm> //所属头文件 sort(begin,end,cmp); //其中cmp参数可以省略,省略后默认 ...
- ABP源码uml类图
陆陆续续学习ABP框架有一段时间了,阳光铭睿的入门教程和HK Zhang的源码分析文章对我的学习帮助都很大.之所以会花这么大工夫去学习ABP.看ABP的源代码,一是因为本人对于DDD也非常有兴趣,AB ...
- 苹果微信内置浏览器cookie
苹果微信内置浏览器cookie会被自动清掉,但safari不会清除,原因还未找到,解决方法是把前端把数据通过header传到后台