hdu2588 gcd 欧拉函数
GCD
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1567 Accepted Submission(s): 751
(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.
1 1
10 2
10000 72
6
260
并且gcd(x,N)>= M,结果为所有N/x的欧拉函数之和。
因为x是N的约数,所以gcd(x,N)=x >= M;
设y=N/x,y的欧拉函数为小于y且与y互质的数的个数。
设与y互质的的数为p1,p2,p3,…,p4
那么gcd(x* pi,N)= x >= M。
也就是说只要找出所有符合要求的y的欧拉函数之和就是答案了。
至于为何用ans+=Euler(n/i0而不是直接加n/i,这便是为了查重,防止出现重复
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
int kase=0;
LL Euler(LL n)
{
LL ans=n;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
ans-=ans/i;
while(n%i==0) n/=i;
}
}
if(n>1) ans-=ans/n;
return ans;
}
int main()
{
int t;
cin>>t;
__int64 n,m;
while(t--)
{
kase=0;
scanf("%I64d%I64d",&n,&m);
int num=(int)sqrt(n+0.5);
//cout<<num<<endl;
for(int i=1;i<num;i++)
{
if(n%i==0)
{
if(n/i>=m)
kase+=Euler(i);
if(i>=m)
kase+=Euler(n/i);
}
}
//cout<<kase<<endl;
// cout<<Euler(100)<<endl;
if(num*num==n&&num>=m) kase+=Euler(num);
cout<<kase<<endl;
}
return 0;
}
hdu2588 gcd 欧拉函数的更多相关文章
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- 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 ...
- HDU 2588 GCD (欧拉函数)
GCD Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- Bzoj-2818 Gcd 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x ...
- BZOJ2818: Gcd 欧拉函数求前缀和
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 如果两个数的x,y最大公约数是z,那么x/z,y/z一定是互质的 然后找到所有的素数,然后用欧拉函数求一 ...
- 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 Submiss ...
- 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 ...
随机推荐
- Intellij idea配置springMvc4.2.6
Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面. 环境: Intellij iead 2016.1 java version " ...
- Vi命令详解
Vi有三种模式,分别为命令行模式.一般模式和编辑模式.在命令行输入“Vi 文件名”,即可进入Vi.常用命令如下:一.一般模式翻页[Ctrl]+[f]: 向下翻一页,相当于[Page Down]按键.[ ...
- js实现网页收藏功能,动态添加删除网址
<html> <head> <title> 动态添加删除网址 </title> <meta charset="utf-8"&g ...
- 利用redis协助mysql数据库搬迁
最近公司新项目上线,需要数据库搬迁,但新版本和老版本数据库差距比较大,关系也比较复杂.如果用传统办法,需要撰写很多mysql脚本,工程量虽然不大,但对于没有dba的公司来说,稍微有点难度.本人就勉为其 ...
- 参数解析argparse模块
argparse,python的一个命令行解析模块 import argparse #创建一个命令行解析器 parser = argparse.ArgumentParser() #增添参数 parse ...
- Hibernate学习笔记--使用ThreadLocal
参考资料: http://blog.sina.com.cn/s/blog_7ffb8dd5010146i3.html http://lavasoft.blog.51cto.com/62575/5192 ...
- iOS开发 自定义navigationleftItem 之后手势失效的问题
@property (nonatomic, strong) UIViewController *currentShowVC; //设置代理 self.navigationController.inte ...
- UITableView常用属性和方法 - 永不退缩的小白菜
UITableView常用属性和方法 - 永不退缩的小白菜 时间 2014-05-27 01:21:00 博客园精华区原文 http://www.cnblogs.com/zhaofucheng11 ...
- 转摘--如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等
http://www.vaikan.com/use-multiple-cpu-cores-with-your-linux-commands/ 你是否曾经有过要计算一个非常大的数据(几百GB)的需求?或 ...
- logstash match
[elk@zjtest7-frontend config]$ cat stdin04.conf input { stdin { } } filter { # drop sleep events gro ...