hdu4497 GCD and LCM
GCD and LCM
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 78 Accepted Submission(s): 43
Note, gcd(x, y, z) means the greatest common divisor of x, y and z, while lcm(x, y, z) means the least common multiple of x, y and z.
Note 2, (1, 2, 3) and (1, 3, 2) are two different solutions.
The next T lines, each contains two positive 32-bit signed integers, G and L.
It’s guaranteed that each answer will fit in a 32-bit signed integer.
6 72
7 33
0
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
#define MAXN 100000
int num[MAXN];
int main()
{
int tcase,n,m,i,ans,sum,tempm;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%d%d",&n,&m);
memset(num,0,sizeof(num));
if(m%n!=0)
{
printf("0\n");
continue;
}
m=m/n;tempm=sqrt(m)+1;
for(i=2,ans=0;i<=tempm;i++)
{
if(m%i==0)
{
while(m%i==0)
{
num[ans]++;m/=i;
}
ans++;
}
}
if(m!=1)
num[ans++]=1;
for(sum=1,i=0;i<ans;i++)
sum*=6*num[i];
printf("%d\n",sum);
}
return 0;
}
hdu4497 GCD and LCM的更多相关文章
- HDU4497 GCD and LCM(数论,质因子分解)
HDU4497 GCD and LCM 如果 \(G \% L != 0\) ,那么输出 \(0\) . 否则我们有 \(L/G=(p_1^{r_1})\cdot(p_2^{r_2})\cdot(p_ ...
- HDU4497——GCD and LCM
这个题目挺不错的,看到是通化邀请赛的题目,是一个很综合的数论题目. 是这样的,给你三个数的GCD和LCM,现在要你求出这三个数有多少种可能的情况. 对于是否存在这个问题,直接看 LCM%GCD是否为0 ...
- hdu4497 GCD and LCM ——素数分解+计数
link:http://acm.hdu.edu.cn/showproblem.php?pid=4497 如果G%L != 0,说明一定无解. 把K = G / L质数分解,G / L = p1^t1 ...
- HDOJ 4497 GCD and LCM
组合数学 GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- hdu 4497 GCD and LCM 数学
GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...
- GCD 与 LCM UVA - 11388
题目链接: https://cn.vjudge.net/problem/23709/origin 本题其实有坑 数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的 思路是最大公因数的倍 ...
- 简单数论总结1——gcd与lcm
并不重要的前言 最近学习了一些数论知识,但是自己都不懂自己到底学了些什么qwq,在这里把知识一并总结起来. 也不是很难的gcd和lcm 显而易见的结论: 为什么呢? 根据唯一分解定理: a和b都可被分 ...
- poj 2429 GCD & LCM Inverse 【java】+【数学】
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9928 Accepted: ...
- HDU 4497 GCD and LCM (合数分解)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
随机推荐
- SQL 死锁进程查询
use master go declare @spid int,@bl int DECLARE s_cur CURSOR FOR ,blocked ) a ) b where a.blocked=sp ...
- flex socket policy
@ flex的as3代码是具备使用origin tcp socket通信能力的. @ 如果是flex builder本机调试,那么可以直连tcp的server. @ 如果flex发布在webserve ...
- configure: error: lzo enabled but missing
注意:yum安装的无效,需要手动下载源码安装. wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz tar zx ...
- SQL 列转行,即多行合并成一条
需求:按照分组,将多条记录内容合并成一条,效果如下: 数据库示例: CREATE TABLE [t2]([NID] [bigint] NULL,[district] [nvarchar](255) N ...
- jquery实现回车键触发事件
键盘事件有3: keydown,keypress,keyup,分别是按下,按着没上抬,上抬键盘 . 正确代码为: $(document).keyup(function(event){ if(event ...
- OC学习那些事:第一个OC类
一.创建一个新的OC类: 1.点击File->New File,打开Choose a template for your new file窗口,选择Objective-C class,点击Nex ...
- web语义化,从松散到实战
GitHub:http://liu12fei08fei.github.io/html/4semantic.html web语义化,从松散到实战 在这篇文章之前,我放弃了很多次,写关于语义化方面的文章: ...
- SqlServer收缩日志文件
通过收缩的方法可以释放所占空间. 第一步:将数据库的模式调整为简单模式 右击数据库名->'属性'->'选项'->恢复模式改成'简单'->点'确定'按钮. 第二步:收缩文件 右键 ...
- Error : The specified component was not reported by the VSS writer (Error 517) in Windows Server 2012 Backup
Error : The specified component was not reported by the VSS writer (Error 517) in Windows Server 201 ...
- 使用结构struct作为Dictionary<TKey,TValue>的键
我们经常用简单数据类型,比如int作为泛型Dictionary<TKey,TValue>的key,但有时候我们希望自定义数据类型作为Dictionary<TKey,TValue> ...