HDU 2588 GCD------欧拉函数变形
GCD
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 812 Accepted Submission(s): 363
(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
/*
题意:求1<=X<=N 满足GCD(X,N)>=M. 思路:if(n%p==0 && p>=m) 那么gcd(n,p)=p,
求所有的满足与n的最大公约数是p的个数,
就是n/p的欧拉值。
因为与n/p互素的值x1,x2,x3....
满足 gcd(n,x1*p)=gcd(n,x2*p)=gcd(n,x3*p).... 枚举所有的即可。
*/ #include<stdio.h>
#include<stdlib.h>
#include<string.h> int Euler(int n)
{
int i,temp=n;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
while(n%i==)
n=n/i;
temp=temp/i*(i-);
}
}
if(n!=)
temp=temp/n*(n-);
return temp;
} void make_ini(int n,int m)
{
int i,sum=;
for(i=;i*i<=n;i++)//!!
{
if(n%i==)
{
if(i>=m)
sum=sum+Euler(n/i);
if((n/i)!=i && (n/i)>=m)//!!
sum=sum+Euler(i);
}
}
printf("%d\n",sum);
} int main()
{
int T,n,m;
while(scanf("%d",&T)>)
{
while(T--)
{
scanf("%d%d",&n,&m);
make_ini(n,m);
}
}
return ;
}
HDU 2588 GCD------欧拉函数变形的更多相关文章
- 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 ...
- 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 ...
- hdu 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 1695 GCD 欧拉函数 + 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1695 要求[L1, R1]和[L2, R2]中GCD是K的个数.那么只需要求[L1, R1 / K] 和 [L ...
- HDU 1695 GCD 欧拉函数+容斥原理+质因数分解
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:在[a,b]中的x,在[c,d]中的y,求x与y的最大公约数为k的组合有多少.(a=1, a ...
- GCD - Extreme(欧拉函数变形)
题目链接:https://vjudge.net/problem/UVA-11426 题目大意: 给出整数n∈[2,4000000],求解∑gcd(i,j),其中(i,j)满足1≤i<j≤n. 的 ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- HDU 2824 简单欧拉函数
1.HDU 2824 The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...
随机推荐
- Day 27 类的进阶-反射
11. __new__ 和 __metaclass__ 阅读以下代码: 1 2 3 4 5 6 class Foo(object): def __init__(self): pass obj = Fo ...
- Zimbra无需登录RCE漏洞利用
2019年3月13号,一名国外的安全研究员在他的博客上公布了zimbra RCE漏洞相关信息,但其中并未提到一些漏洞利用细节. 经过一段时间努力,根据网上各位大牛的分析和我自己的理解,在此我将整个漏洞 ...
- neutron openvswitch + vxlan 通讯
- javar入门——基本数据类型
Java中的数据类型分为两类: 基本数据类型(或者称为原生数据类型) 引用数据类型 基本数据类型 8种:6种基本数据类型,1种字符型,1种布尔型 byte,short,int,long,float,d ...
- Linux下安装python虚拟环境(virtualenv,vritulaenvwrapper)
一.virtualenv virtualenv是如何创建"独立"的Python运行环境的呢? 原理很简单,就是把系统Python复制一份到virtualenv的环境,用命令sour ...
- 2017 NAIPC A:Pieces of Parentheses
my team solve the problem in the contest with similar ideathis is a more deep analysis The main idea ...
- Google Guava 类库简介
Guava 是一个 Google开发的 基于java的类库集合的扩展项目,包括 collections, caching, primitives support, concurrency librar ...
- centos6创建用户,设置ssh登录
创建用户 #创建用户 useradd -s /sbin/nologin mysql useradd –d /usr/china -m china #设置密码 passwd mysql passwd c ...
- Storm系列一: Storm初步
初入Storm 前言 学习Storm已经有两周左右的时间,但是认真来说学习过程确实是零零散散,遇到问题去百度一下,找到新概念再次学习,在这样的一个循环又不成体系的过程中不断学习Storm. 前人栽树, ...
- Day1 Excel基本知识
1. 数据分析过程 2. 2016增强版Excel 特性 科学管理,科学决策的工具 精细化,量化分析的工具 3. Excel 学什么? 计算机解决问题的思维(抽象) 数据分析的思路与方法 掌握技巧和方 ...