GCD and LCM

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4497

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

HINT

题意

问你有多少个三元组,可以使得他们lcm等于b,gcd等于a

题解:

和二元组一样做,显然直接b/a之后,分解质因数,然后直接跑排列组合就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll ans[maxn];
int main()
{
//test;
int t=read();
while(t--)
{
memset(ans,,sizeof(ans));
ll a,b;
scanf("%lld%lld",&a,&b);
if(b%a)
{
cout<<""<<endl;
continue;
}
ll c=b/a;
ll kiss=;
int tot=;
for(int i=;i<=c;i++)
{
if(c==)
break;
if(c%i==)
{
while(c%i==)
ans[tot]++,c/=i;
tot++;
}
}
for(int i=;i<tot;i++)
{
if(ans[i])
kiss*=ans[i]*;
}
cout<<kiss<<endl;
}
}

hdu 4497 GCD and LCM 数学的更多相关文章

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

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

  2. HDU 4497 GCD and LCM(数论+容斥原理)

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

  3. 数论——算数基本定理 - HDU 4497 GCD and LCM

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

  4. hdu 4497 GCD and LCM (非原创)

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

  5. HDU 4497 GCD and LCM (数学,质数分解)

    题意:给定G,L,分别是三个数最大公因数和最小公倍数,问你能找出多少对. 析:数学题,当时就想错了,就没找出规律,思路是这样的. 首先G和L有公因数,就是G,所以就可以用L除以G,然后只要找从1-(n ...

  6. HDU 4497 GCD and LCM(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

  7. HDU 4497 GCD and LCM (数论)

    题意:三个数x, y, z. 给出最大公倍数g和最小公约数l.求满足条件的x,y,z有多少组. 题解:设n=g/l n=p1^n1*p2^n2...pn^nk (分解质因数 那么x = p1^x1 * ...

  8. hdu 4497 GCD and LCM(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)

    质分解 + 简单计数.当时去比赛的时候太年轻了...这道题都没敢想.现在回过头来做了一下,发现挺简单的,当时没做这道题真是挺遗憾的.这道题就是把lcm  / gcd 质分解,统计每个质因子的个数,然后 ...

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

    链接 :  http://acm.hdu.edu.cn/showproblem.php?pid=4497 假设G不是L的约数 就不可能找到三个数. L的全部素因子一定包括G的全部素因子 而且次方数 ...

随机推荐

  1. delphi 712 Word 2

    //导出Wordprocedure TFrm_Computing.ExportWord(aFileName: string; aFileType: string);var wordApp, WordD ...

  2. c++中调用cygwin/x使用ncl

    1.C++中调用程序:   ShellExecute(NULL,L"open",L"cmd.exe",L"/c d: & cd cygwin ...

  3. linux下磁盘的挂载与卸载

    Linux下每个文件系统都有独立的inode,block,super block等信息,这个文件系统要挂载到目录树才可以使用,将文件系统与目录树结合的操作称为挂载,反之则为卸载. 也就是说,挂载点一定 ...

  4. C++读取二进制文件(某特定格式)

    该格式也不复杂,就是一个二进制文件,格式为:8个通道,每个通道2字节,都为整数,最后两个通道都是0x03FF == 1023d,文件中中若干个8通道. 有个小细节就是:下面代码中 infile.rea ...

  5. CAT XQX --- 省市三级级联实现说明

    最终效果: 满足要求, 上代码 : 1.   需要调用这个控件 的地方:添加引用,因为里面写着逻辑呢..... <script type="text/javascript" ...

  6. iOS App中数据加载的6种方式

    我们看到的APP,往往有着华丽的启动界面,然后就是漫长的数据加载等待,甚至在无网络的时候,整个处于不可用状态.那么我们怎么处理好界面交互中的加载设计,保证体验无缝衔接,保证用户没有漫长的等待感,而可以 ...

  7. [转] 編程風格要素-The Elements of Programming Style 中文英文中英對照

    转自: http://www.loliman3000.com/tech/2fe33ce32906f0302412881.php 下面的程序風格規則提煉自Brian Kernighan和P. J. Pl ...

  8. Tips for android

    对话框样式Activity获得窗口外点击事件(注册Activity时指明theme为adnroid:Theme.Dialog) 在API11之后添加了setFinishOnTouchOutside() ...

  9. something: 重构、正则、vim -- clwu

    项目需要做一个db table 操作的小工具. 从phpMyAdmin上拷贝了一些代码过来修改,但我有没有足够的时间把所有拷贝过来的代码都重构修改和测试完,于是希望后面接手的同事在需要修改这些代码时能 ...

  10. 转】MyEclipse使用总结——在MyEclipse中设置jsp页面为默认utf-8编码

    原博文出自于:http://www.cnblogs.com/xdp-gacl/p/3496161.html 感谢! 在MyEclispe中创建Jsp页面,Jsp页面的默认编码是"ISO-88 ...