zoukankan      html  css  js  c++  java
  • LuoguP1069 细胞* (质因数分解)

    通过质因数分解可以把很大的数唯一分解为有限个质数的乘积,能够很好的比较两个数。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<map>
    #include<queue>
    #include<vector>
    #include<string>
    #include<fstream>
    using namespace std;
    #define rep(i, a, n) for(int i = a; i <= n; ++ i)
    #define per(i, a, n) for(int i = n; i >= a; -- i)
    typedef long long ll;
    const int N = 2e5+105;
    const int mod = 998244353;
    const double Pi = acos(- 1.0);
    const ll INF = 1e12;
    const int G = 3, Gi = 332748118;
    ll qpow(ll a, ll b) { ll res = 1; while(b){ if(b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1;} return res; }
    ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    //
    
    
    
    ll n, m1, m2;
    ll p[N], c[N], m, res;
    map<ll, ll> mp;
    vector<ll> base;
    
    
    void div(ll x){
        m = 0;
        for(ll i = 2; i * i <= x; ++ i){
            if(x % i == 0){
                p[++ m] = i;
                c[m] = 0;
                while(x % i == 0) c[m] ++, x /= i;
            }
        }
        if(x > 1) p[++ m] = x, c[m] = 1;
    }
    
    ll solve(ll x){
        div(x);
       
        if(m < (ll)base.size()) return INF;
        ll l = 1, r = 0, num = 0, temp = 0;
        while(r < base.size()){
            num = 0;
            ll pp = base[r], cc = mp[base[r]];
            if(p[l] == pp){
                if(cc <= c[l]) num = 0;
                else num = (cc + c[l] - 1) / c[l];
                temp = max(temp, num);
                l ++;
                r ++;
            }
            else if(p[l] < pp){
                l ++;
                if(l > m){
                    return INF;
                }
            }
            else{
               l ++;
               if(l > m){
                   return INF;
               }           
            }
        }
        return temp;
    }
    
    int main()
    {
        scanf("%lld",&n);
        scanf("%lld%lld",&m1,&m2);
        if(m1 == 1){
            printf("0
    ");
            return 0;
        }
        div(m1);
        rep(i,1,m){
            mp[p[i]] = m2 * c[i];
            base.push_back(p[i]);
        }
        sort(base.begin(),base.end());
        res = INF;
        rep(i,1,n){
            ll s;
            scanf("%lld",&s);
            res = min(res, solve(s));
        }
        if(res == INF) printf("-1
    ");
          else printf("%lld
    ",res);
        return 0;
    }
    
  • 相关阅读:
    GitLab 自动触发 Jenkins 构建
    微服务监控探索
    使用QUIC
    非对称加密与证书(上篇)
    Vue框架核心之数据劫持
    如何实现最佳的跨平台游戏体验?Unity成亮解密实时渲染
    网易易盾验证码的安全策略
    CodeForces 339C Xenia and Weights(暴力求解DFS)
    CodeForces 339D Xenia and Bit Operations (线段树)
    CodeForces 339B Xenia and Ringroad(水题模拟)
  • 原文地址:https://www.cnblogs.com/A-sc/p/12822383.html
Copyright © 2011-2022 走看看