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. 解决CIFilter滤镜后图片大小和方向发生变化

    调用contextWithOptions:和createCGImage: fromRect:方法创建CIContext.与以往不同的地方是CIImage没有frame与bounds属性:只有exten ...

  2. Python编程练习题学习汇总

    实例一:数学计算 简述:这里有四个数字,分别是:1.2.3.4提问:能组成多少个互不相同且无重复数字的三位数?各是多少? Python解题思路分析:可填在百位.十位.个位的数字都是1.2.3.4.组成 ...

  3. redis-py说明文件(转)

    转自:http://blog.sina.com.cn/s/blog_6262a50e0101574h.html 原文:https://github.com/andymccurdy/redis-py r ...

  4. Linux线程 之 线程 线程组 进程 轻量级进程(LWP) -systemtap -mysql

    http://blog.chinaunix.net/uid-24774106-id-3650136.html http://blog.itpub.net/15480802/viewspace-7627 ...

  5. java基础学习总结——抽象类

    一.抽象类介绍

  6. CNZZ站点流量统计原理简析

    这是我的域名www.iyizhan.com.暂无内容,当中仅仅有一个页面index.html. 在index.html上放置了例如以下的 js 脚本: <script  src="ht ...

  7. 使用C#中的ref关键字,用2个简单例子来说明

    在C#中,如果在方法参数前面加上ref关键字,说明参数传递的是引用,而不是值.如何理解呢? 参数是简单类型的例子 static void Main(string[] args) { string te ...

  8. Microsoft office2016打开很慢解决

    (1)打开Excel(word.ppt也可以),进入空白纸张,或者随便打开或新建一个文件也行,然后点击左上角“文件”按钮,进入点击“选项”. (2)然后在“常规”选项里,拉到最下面,把“”这个选项去除 ...

  9. jsondataobjects

    jsondataobjects GITHUB: https://github.com/ahausladen/jsondataobjects.git 跨平台JSON库 Json Data Objects ...

  10. arcgis python 沿线生成点

    # coding: utf-8 """ Source Name: generatepointsfromlines.py Version: ArcGIS 10.4/Pro ...