hdu2588-GCD-(欧拉函数+分解因子)
(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
翻译:给出n和m,1<=x<=n,求x符合gcd(x,n)>=m有多少个。
解题过程:
令d=gcd(x,n),显然d是n的因子,并且是x和n的最大公因子,则gcd(x/d,n/d)=1
对于每个d,令y=n/d,找有多少个x/d满足gcd(x/d,y)=1。
欧拉函数登场,累加y的欧拉函数值。
#include <iostream>
#include<stdio.h>
#include <algorithm>
#include<string.h>
#include<cstring>
#include<math.h>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std; ll euler(ll x)
{
ll res=x;
for(ll i=;i*i<=x;i++)
{
if(x%i==)
{
res=res/i*(i-);
while(x%i==)
x=x/i;
}
}
if(x>)
res=res/x*(x-);
return res;
} int main()
{ ll t,n,m,sum;
scanf("%lld",&t);
while(t--)
{
sum=;
scanf("%lld%lld",&n,&m);
int q=sqrt(n);
ll i;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
if(i>=m)
sum=sum+euler(n/i);
if((n/i)>=m)
sum=sum+euler(i);
}
}
i--;
if(i*i==n && i>=m)
sum=sum-euler(i);
printf("%lld\n",sum);
}
return ;
}
hdu2588-GCD-(欧拉函数+分解因子)的更多相关文章
- hdu2588 gcd 欧拉函数
GCD Time Limit: 2000/1000 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 ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- HDU 2588 GCD (欧拉函数)
GCD Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- hdu 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 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 ...
- 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一定是互质的 然后找到所有的素数,然后用欧拉函数求一 ...
随机推荐
- oracle start with connect by prior 递归查询用法
start with 子句:遍历起始条件,有个小技巧,如果要查父结点,这里可以用子结点的列,反之亦然. connect by 子句:连接条件.关键词prior,prior跟父节点列parentid放在 ...
- angularjs路由相关知识
angular.module('app').config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRout ...
- 关于elment-ui树形控件Tree的使用
如果简单使用的tree树形控件,按照Element ui Tree 树形控件 官方文档使用即可,基本上能够完成大部分的需求. 但是如果需要对树形结构进行额外操作,仅仅根据官方文档提供的方案的话,可能就 ...
- day6--面向对象初识
一面向过程与面向对象 面向过程: 流水线式的思维,顺着流程进行下去,类似于代码的堆叠,重视步骤 优点:不需要考虑太多东西,想到一个功能就写一个功能,堆叠代码 缺点:过程往往是先后执行的,要想变换功能或 ...
- django-权限验证场景
1.需要登录才能够访问的验证 from django.contrib.auth.decorators import login_required # 登录装饰器 # method_decorator ...
- [UGUI]图文混排(二):Text源码分析
UGUI源码: https://bitbucket.org/Unity-Technologies/ui/downloads/?tab=tags 首先下载一份UGUI源码,这里我下载的版本是5.3.2f ...
- mongodb的副本集|备份|恢复备份
复制(副本集) 什么是复制 复制提供了数据的冗余备份,并在多个服务器上存储数据副本,提高了数据的可用性,并可以保证数据的安全性 复制还允许从硬件故障和服务中断中恢复数据 为什么要复制 数据备份 数据灾 ...
- 6.简单提取小红书app数据(简单初步试采集与分析)-1
采集小红书数据爬虫:1.本来是要通过app端的接口去直接采集数据,但是app接口手机端设置本地代理这边开启抓包后就不能正常访问数据.所以就采用了微信小程序里的小红书app接口去采集数据. 2.通过 f ...
- mysqld服务启动失败, Failed to restart mysqld.service: Unit not found.
-bash-4.2# service mysqld restart Redirecting to /bin/systemctl restart mysqld.serviceFailed to rest ...
- Centos7 用户登录失败N次后锁定用户禁止登陆
参考网站:https://blog.csdn.net/qq_33285112/article/details/78813369 未试 思路是查找/var/log/secure中验证失败且出现的次数较 ...