• [hdu4497]分解质因数


    题意:求满足gcd(x,y,z)=G,lcm(x,y,z)=L的x,y,z的解的个数。

    大致思路:首先如果L % G != 0那么无解,否则令u = L / G,问题变为,gcd(r,s,t)=1,lcm(r,s,t)=u的解的个数。然后将u分解质因数,令u=a1p1*...*akpk,考虑一种质因数ai,它不可能同时出现在r,s,t中,枚举所有情况:(1)只出现在r或s或t中,这3种情况答案都为1 (2)出现在r和s或r和t或s和t中,这3种情况答案都为2(pi-1)+1=2pi-1,所以对每一种因子答案为3*(2pi-1)+3=6pi,由乘法原理,最后答案为6k*p1*p2*...*pk。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<stdlib.h>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    typedef long long LL;
    int b, a;
    LL solve() {
        int x = b / a;
        int p[100], c = 0;
        for (int i = 2; (LL)i * i <= x; i ++) {
            while (x % i == 0) {
                p[c ++] = i;
                x /= i;
            }
        }
        if (x > 1) p[c ++] = x;
        p[c ++] = 0;
        LL ans = 1;
        int k = 0, last = 0;
        for (int i = 1; i < c; i ++) {
            if (p[i] != p[i - 1]) {
                k ++;
                ans *= (i - last);
                last = i;
            }
        }
        for (int i = 0; i < k; i ++) ans *= 6;
        return ans;
    }
    int main(){
        int T;
        cin >> T;
        while (T --) {
            cin >> a >> b;
            if (b % a != 0) puts("0");
            else cout << solve() << endl;
        }
        return 0;
    }
  • 相关阅读:
    BZOJ1787 [Ahoi2008]Meet 紧急集合[结论题]
    poj3728 The merchant[倍增]
    poj2750 Potted Flower[线段树]
    poj2482 Stars in Your Window[扫描线]
    poj2182 Lost Cows[BIT二分]
    UVA12096 The SetStack Computer
    第05组(65) 需求分析报告
    团队介绍与选题报告
    数据采集技术第三次作业
    结对编程作业
  • 原文地址:https://www.cnblogs.com/jklongint/p/4548169.html
Copyright © 2020-2023  润新知