ZCMU-1142: 松哥的困惑VIII

Description

又有一天,又是dp小王子又是偷偷摸摸的找到了松哥:有两个数p,q,已知他们的最大公约数是x,最小公倍数是y,你知道一共有几组(p,q)满足条件嘛?松哥又要向你请教了。

Input

多组测试数据.

每组测试数据有两个整数x,y.(1<=x<=y<=10^7).

Output

对于每组测试数据,输出有几组(p,q)满足条件

Sample Input

3 60

Sample Output

4


如果y不能整除x那么结果为0

否则将y/x拆分为素数连乘形式(例:9450=2*3*3*3*5*5*7;1个2,3个3,2个5,1个7)

输出可以组成几组互质的数

求法:

p和q不能包含相同的素数因子,因此每一种素数因子只能全部放在p或者q里

(例如对于9450,每组p和q必定有一个整除25,另一个与25互质)

为了让程序跑快点,我把可能用到的数据都提前求出来了


#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int main()
{
    //筛素数
    bool prime[4005];
    int p[555],pcount=0;
    fill(prime, prime+4005, true);
    int i,j;
    for (i=2; i<4005; i++) {
        if (!prime[i])
            continue;
        p[pcount++] = i;
        j = 2*i;
        while (j<4005) {
            prime[j] = false;
            j += i;
        }
    }

    //2的n次方
    int mod2[13] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096};

    //运行
    int x,y;
    while (~scanf("%d%d",&x,&y)) {
        if (y % x) {
            printf("0\n");
            continue;
        }else{
            y /= x;
            j = 0;
            for (i=0; i

 

你可能感兴趣的:(zcmu浙中医)