zoukankan      html  css  js  c++  java
  • LightOj 1220

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1220

    题意:已知 x=b中的 x 求最大的 p,其中 x b p 都为整数

    x = (p1a1*p2a2*p3a3*...*pkak), pi为素数;则结果就是gcd(a1, a2, a3,...,ak);

    当x为负数时,要把ans缩小为奇数;

    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <vector>
    #include <math.h>
    using namespace std;
    typedef long long LL;
    const int oo = 0xfffffff;
    const int N = 1e6+5;
    const double eps = 1e-8;
    
    
    int f[N], p[N], k = 0;
    void Init()
    {
        for(int i=2; i<N; i++)
        {
            if(!f[i]) p[k++] = i;
            for(int j=i; j<N; j+=i)
                f[i] = 1;
        }
    }
    
    int gcd(int a, int  b)
    {
        return b == 0 ? a : gcd(b, a%b);
    }
    
    int cnt[N];
    
    int main()
    {
        Init();
    
        int T, t = 1;
    
        scanf("%d", &T);
    
        while(T--)
        {
            LL n;
            int flag = 0;
    
            scanf("%lld", &n);
    
            if(n < 0)
            {
                n = -n;
                flag = 1;
            }
    
            int ans = 0;
    
            memset(cnt, 0, sizeof(cnt));
    
            for(int i=0; i<k && (LL)p[i]*p[i]<=n; i++)
            {
                while(n%p[i] == 0)
                {
                    cnt[i]++;
                    n /= p[i];
                }
                if(ans == 0 && cnt[i])
                    ans = cnt[i];
                else if(cnt[i])
                    ans = gcd(cnt[i], ans);
            }
    
            if(n > 1 || ans == 0)
                ans = 1;
    
            if(flag)///负数,结果一定是奇数;
            {
                while(ans%2 == 0)
                    ans /= 2;
            }
            printf("Case %d: %d
    ", t++, ans);
        }
        return 0;
    }
    /*
    -1000000
    1
    
    3
    1
    */
    View Code
  • 相关阅读:
    django基础之ORM基础知识
    Centos7 搭建sonarQube
    centos7安装部署SVN
    centos7.5 SVN 搭建
    centos 7 部署 zookeeper
    centos7 发送邮件
    Centos7安装配置Gitlab-CE
    openldap 双主模式部署
    K8s一键安装
    ELK实战部署
  • 原文地址:https://www.cnblogs.com/zhengguiping--9876/p/6016425.html
Copyright © 2011-2022 走看看