# GCD and LCM

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 675    Accepted Submission(s): 312

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

題意： gcd(x,y ,z) = G  lcm(x, y , z)= L， 問有多少種這樣的組合數（x, y,z），題目要求有序，故為排列問題。
1： 我們可以轉換為求gcd(x/G , y/G , z/G)=1  ,   lcm (x/G, y/G ,z/G) = L/G;  即求gcd(x,y,z)=1  qie  lcm(x,y,z)=n=L/G，的排列數。

2：由於質因子滿足乘法原則 ， 我們對每一個質因子 討論 pi^ri,   由於gcd(x,y,z)=1  ,可以斷定 x,y,z 有個數一定是pi^0次，  由於lcm(x,y,z)=pi^ri*....,我們可以斷定 x,y,z 中一定有一個數能被 pi^ri 整除, 那么另一個數 就可以取  0 ，1，...， ri 中的任意一個數。因此，我們將 ri個 pi  放入 x, y, z 三個數中， 分兩種情況：

```#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#define N 100005
using namespace std;
map<int , int >factor;
map<int ,int >::iterator it;
void prime(int x)
{
int i,num;
for(i=2;i*i<=x ;i++)
{
if(x%i ==0){
num=0;
while(x%i ==0)
{
x/=i;
num++;
}
factor[i]=num;
}
}
if(x>1)
factor[x]=1;
}
int main()
{
int t,g,l,n,sum;
cin>>t;
while(t--)
{
sum=1;
factor.clear();
cin>>g>>l;
if(l%g)
{
puts("0");
continue;
}
n=l/g;
prime(n);
for(it=factor.begin(); it!=factor.end() ; it++)
sum*=(6*it->second);
cout<<sum<<endl;
}
return 0;
}```