zoukankan      html  css  js  c++  java
  • HDU 4497 GCD and LCM (分解质因数)

    链接 :
    

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

    假设G不是L的约数 就不可能找到三个数。

    L的全部素因子一定包括G的全部素因子 而且次方数一定大于等于G的。仅仅须要三个数 对于每个素因子的次方数 三个的最小值是G的,最大值是L的。考虑三个相应的次方数都不一样。那么当中两个是确定的 一个是G的一个是L的 剩下的一个在G和L的之间。

    算上排列 总共同拥有6种。或者当中两个是一样的,那么也有6种情况。

    最后能够合并计算。


    //#pragma comment(linker, "/STACK:10240000,10240000")
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #define mod 4294967296
    #define MAX 0x3f3f3f3f
    #define lson o<<1, l, m
    #define rson o<<1|1, m+1, r
    #define SZ(x) ((int)ans.size())
    #define MAKE make_pair
    #define INFL 0x3f3f3f3f3f3f3f3fLL
    #define mem(a) memset(a, 0, sizeof(a))
    const double pi = acos(-1.0);
    const double eps = 1e-9;
    const int N = 200005;
    const int M = 20005;
    typedef __int64 ll;
    using namespace std;
    
    ll a, b;
    struct C {
        ll num, cnt;
    } s[N], t[N];
    int T;
    
    int Ini(ll a, C* f) {
        int tmp = sqrt(1.0*a + 0.5), e = 0;
        for(int i = 2; i <= tmp; i++) {
            if(a % i == 0) {
                int k = 0;
                while(a % i == 0) {
                    k++;
                    a /= i;
                }
                f[e].num = i;
                f[e++].cnt = k;
            }
        }
        if(a != 1) {
            f[e].cnt = 1;
            f[e++].num = a;
        }
        return e;
    
    }
    
    int main()  {
    
        //freopen("in.txt","r",stdin);
        cin >> T;
        while(T--) {
            cin >> a >> b;
            if(b % a) {
                puts("0");
                continue;
            }
            mem(s);
            mem(t);
            int n = Ini(a, s);
            int m = Ini(b, t);
    
            ll ans = 1, x;
            int fr = 0;
            for(int i = 0; i < m; i++) {
                if(t[i].num == s[fr].num) {
                    x = t[i].cnt - s[fr].cnt;
                    fr++;
                    if(x) ans *= x * 6;
                } else ans *= t[i].cnt * 6;
    
            }
            cout << ans << endl;
        }
        return 0;
    }

  • 相关阅读:
    redis该怎么用
    cookie和session的比较
    web常见攻击
    请大神指导从大日志文件中统计关键字次数的办法
    apache中 MaxClients 与MaxRequestsPerChild
    如何提高缓存命中率
    CSU-ACM2018暑假集训比赛1
    CodeForces
    CodeForces
    CodeForces
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6693926.html
Copyright © 2011-2022 走看看