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

Problem Description
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and lcm(x, y, z) = L?

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.
 
Input
First line comes an integer T (T <= 12), telling the number of test cases.

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.
 
Output
For each test case, print one line with the number of solutions satisfying the conditions above.
 
Sample Input
2
6 72
7 33
 
Sample Output
72
0
 
Source
 
Recommend
liuyiding
很明显,m/n!=0的话,就直接输出0就可以了!否刚,直接分解质因数m/n,找到,每个质因子的个数,这样,我们,就可以得出每个质因数为a1^k1,那是题目就是要把这k1个a1分到三个数中,那么排列组合就是k1*A(3,2),也就是,6*k1,种,直接算出来就行了!
#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的更多相关文章

  1. 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_ ...

  2. HDU4497——GCD and LCM

    这个题目挺不错的,看到是通化邀请赛的题目,是一个很综合的数论题目. 是这样的,给你三个数的GCD和LCM,现在要你求出这三个数有多少种可能的情况. 对于是否存在这个问题,直接看 LCM%GCD是否为0 ...

  3. hdu4497 GCD and LCM ——素数分解+计数

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4497 如果G%L != 0,说明一定无解. 把K = G / L质数分解,G / L = p1^t1 ...

  4. HDOJ 4497 GCD and LCM

    组合数学 GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  5. 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 ...

  6. GCD 与 LCM UVA - 11388

    题目链接: https://cn.vjudge.net/problem/23709/origin 本题其实有坑 数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的 思路是最大公因数的倍 ...

  7. 简单数论总结1——gcd与lcm

    并不重要的前言 最近学习了一些数论知识,但是自己都不懂自己到底学了些什么qwq,在这里把知识一并总结起来. 也不是很难的gcd和lcm 显而易见的结论: 为什么呢? 根据唯一分解定理: a和b都可被分 ...

  8. poj 2429 GCD &amp; LCM Inverse 【java】+【数学】

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9928   Accepted:  ...

  9. HDU 4497 GCD and LCM (合数分解)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

随机推荐

  1. Oil Deposits 搜索 bfs 强联通

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  2. 一行代码提取url中querystring的某个key的值

    var itemdata = "OrderFilter=0&ProjectTag=15&DateType=0"; var projectTag = itemdata ...

  3. TPS70345 (ACTIVE) 双路输出低压降 (LDO) 稳压器

    The TPS703xx family of devices is designed to provide a complete power management solution for TI DS ...

  4. linux下安装MYSQL详细配置(转)

      #tar zxvf mysql-5.0.18.tar.gz#cd  mysql-5.0.18 #./configure --prefix=/usr/local/mysql --with-chars ...

  5. centos7 通过kvm+vnc 实现远程桌面虚拟化和创建windows、Linux虚拟机

    感谢朋友支持本博客.欢迎共同探讨交流,因为能力和时间有限.错误之处在所难免,欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  6. ELMAH--Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components 77 out of 90 rated th

    MSDN===http://msdn.microsoft.com/en-us/library/aa479332.aspx PROJECT==https://code.google.com/p/elma ...

  7. 【spring cloud】spring cloud集成zipkin报错:Prometheus requires that all meters with the same name have the same set of tag keys.

    spring boot 2.0.X 的版本,整合zipkin2.10.1 zipkin服务启动后,访问zipkin的UI http://localhost:8002/zipkin/ 页面显示空白,cs ...

  8. 在Windows下编译Emacs

    在Windows下编译Emacs Windows下编译好的Emacs主要有两个版本,一个来自http://nqmacs.sourceforge.net/,另一个来自http://www.crasseu ...

  9. Tomcat集群扩展session集中管理,Memcached-session-manager使用

    研究tomcat做负载均衡的时候如何实现ha,还有就是不采用session复制的方法做集群. 想到的是将session全部存储在后端的缓存服务器中. 正好网上有这么一个工具Memcached-sess ...

  10. 已有数据库(单机)部署Database Vault

    1.停止em和数据库 emctl stop dbconsole shutdown immediate 2.又一次安装DB软件 ./runInstaller 选组件的时候,选中"Oracle ...