E - GCD HDU - 2588
(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.
InputThe first line of input is an integer T(T<=100) representing the number of test cases. The following T lines each contains two numbers N and M (2<=N<=1000000000, 1<=M<=N), representing a test case.OutputFor each test case,output the answer on a single line.Sample Input
3
1 1
10 2
10000 72
Sample Output
1
6
260
题意:给你一个t表示测试组数,每一组数据给你两个数n,m(范围2~1e8),求在小于等于n的数中,有多少数满足gcd(i,n)>=m;
思路:很明显是一个欧拉函数,但是它的gcd不是一是m,因此我们要把它化为m,gcd为一,乘上m,gcd不就是m了吗
因此,我们要找n所有因子,
- 当因子p大于等于m的时, n = p *n/p,这个时候只要知道n/p的欧拉值就可以了euler(n/p),表示的gcd为一,*p,gcd就是p>=m;
- 当因子p,有n/p>=m时,并且保证 n/p !=p,这个时候只要知道p的欧拉值就可以了euler(p),表示的gcd为一,*n/p,gcd就是n/p>=m;
- 两者之间是没有重复的,唯一存在可能重复的就是当n/p=p的时候,特判一下就可以了euler(p),and euler(n/p) 会有重复的部分,但他们的乘项不同,乘出的结果也就不同
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#define Mod 1000000007
using namespace std;
typedef long long ll;
const ll N = +;
map<ll,ll> elh;
long long a,b;
ll sum [N];
ll Euler(ll n)
{
if(n==)return ;
ll res =n;
for(ll i=;i<=n/i;i++)
{
if(n%i==)
{
res = res -res/i;
}
while(n%i==)n/=i;
}
if(n>)res -= res/n;
return res;
}
int main()
{
int t;
cin >>t;
while(t--)
{
scanf("%lld%lld",&a,&b);
ll sum =;
for(int i=;i<=a/i;i++)
{
if(a%i==)
{
if(i>=b)
{
sum +=Euler(a/i);
}
if(a/i>=b&&a/i!=i)
{
sum+=Euler(i);
}
}
}
cout <<sum<<endl;
}
return ;
}
不管前方的路有多么曲折,我都会告诉自己,自己的选择,没有后悔,后退的可能,因为热爱所以坚持,既然已经走上这条路,就走出一点风采!!!
E - GCD HDU - 2588的更多相关文章
- GCD HDU - 2588
输入 N 和 M (2<=N<=1000000000, 1<=M<=N), 找出所有满足1<=X<=N 且 gcd(X,N)>=M 的 X 的数量. Inpu ...
- D - GCD HDU - 1695 -模板-莫比乌斯容斥
D - GCD HDU - 1695 思路: 都 除以 k 后转化为 1-b/k 1-d/k中找互质的对数,但是需要去重一下 (x,y) (y,x) 这种情况. 这种情况出现 x ,y ...
- HDU 2588 思维 容斥
求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...
- HDU 2588 GCD 【Euler + 暴力技巧】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2588 GCD Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 2588 GCD (欧拉函数)
GCD Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- HDU 2588 GCD
题目大意:给定N,M, 求1<=X<=N 且gcd(X,N)>=M的个数. 题解:首先,我们求出数字N的约数,保存在约数表中,然后,对于大于等于M的约数p[i],求出Euler(n/ ...
- HDU 2588 GCD(欧拉函数)
GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 2588 GCD && GCD问题总结
GCD(一) 题目: The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written ( ...
- 题解报告:hdu 2588 GCD(欧拉函数)
Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written ...
随机推荐
- python列表插入--append(), extend(), insert()
append(),extend(), insert()都是列表操作中常用的插入函数.其中前两个均接收一个参数,并插入到列表尾部.最后一个接收两个参数,将参数2插入到参数1之前. 本文主要讨论appen ...
- Docker一
Docker 简介一 背景开发和运维之间因为环境不同而导致的矛盾集群环境下每台机器部署相同的应用DevOps(Development and Operations) 简介 Docker是一个开源的应用 ...
- 【VS开发】malloc申请内存错误分析
每个进程会有4G的虚拟地址空间, malloc得到的的地址都是虚拟地址, 并且当malloc的时候, 操作系统并不会将实际的内存分配给进程的, 所以malloc只会占用进程自身的虚拟地址空间.我以前也 ...
- 字符编码笔记:ASCII,Unicode 和 UTF-8(理解)
1.ASCII 码 美国制定的字符编码规则,对英语字符与二进制位之间的关系做了统一规定. 占一个字节,8 位,最多可表示 2^8 = 256 种状态(字符) 实际共有 128 个字符,只占用一个字节的 ...
- Go语言入门篇-gRPC基于golang & java简单实现
一.什么是RPC 1.简介: RPC:Remote Procedure Call,远程过程调用.简单来说就是两个进程之间的数据交互. 正常服务端的接口服务是提供给用户端(在Web开发中就是浏览器)或者 ...
- Spring boot 新建项目pom.xml文件报错 Failure to transfer org.springframework.boot:spring-boot-maven-plugin
新建项目依赖下载时网络中断导致资源损坏 删除.m2\repository中后缀名为lastUpdated的文件 cd %userprofile%\.m2\repository for /r %i in ...
- cook,session
//发送session request.getSession().setAttribute("user", "zs1"); //发送cookie //需要自动登 ...
- js唤醒手机APP
if (navigator.userAgent.match(/android/i)) { // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 / ...
- Codeforces Round #590 (Div. 3) Editorial
Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...
- thinkphp5分页查询paginate()传递参数
使用paginate()分页,我这里实现的是搜索后分页显示,翻页后传递搜索关键字 www.demo.com/home/search/?k=搜索关键字&page=2 搜索分页源码在: think ...