其他分享
首页 > 其他分享> > LightOJ-1220 Mysterious Bacteria (质因数分解)

LightOJ-1220 Mysterious Bacteria (质因数分解)

作者:互联网

题目:
#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 = 5e5 + 105;
const int mod = 998244353;
const double Pi = acos(- 1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
ll qpow(ll a, ll b) { ll res = 1; while(b){ if(b) 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; }
//

int T;
ll n;
ll p[N], c[N];
ll m;

void div(ll x){
    m = 0;
    for(ll i = 2; i * i<= x; ++ i){
        if(n % i == 0){
            p[ ++ m] = i, c[m] = 0;
            while(n % i == 0) n /= i, c[m] ++;
        }
    }
    if(n > 1) p[++ m] = n, c[m] = 1;
    
}

int main()
{
    scanf("%d",&T);
    rep(Case,1,T) {
        int flag = 0;
        scanf("%lld",&n);
        if(n == 1){
            printf("Case %d: 1\n",Case);
            continue;
        }
        if(n < 0){
            n = -n;
            flag = 1;
        }
        ll res = 0;
        div(n);
        if(m == 1) res = c[m];
        else{
            rep(i,1,m){
                res = gcd(res, c[i]);
            }
        }
        if(flag){
            while(res % 2 == 0) res /= 2;
        }
        printf("Case %d: %lld\n",Case,res);
    }
    return 0;
}


标签:Case,const,因数分解,int,res,ll,LightOJ,Mysterious,include
来源: https://www.cnblogs.com/A-sc/p/12820075.html