merging dua II audio interface_power of one

merging dua II audio interface_power of one题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6623MinimalPowerofPrimeTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):1935AcceptedSub…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6623
Minimal Power of Prime

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1935 Accepted Submission(s): 437

Problem Description
You are given a positive integer n > 1. Consider all the different prime divisors of n. Each of them is included in the expansion n into prime factors in some degree. Required to find among the indicators of these powers is minimal.

Input
The first line of the input file is given a positive integer T ≤ 50000, number of positive integers n in the file. In the next T line sets these numbers themselves. It is guaranteed that each of them does not exceed 10^18.

Output
For each positive integer n from an input file output in a separate line a minimum degree of occurrence of a prime in the decomposition of n into simple factors.

Sample Input

5
2
12
108
36
65536

Sample Output

1
1
2
2
16

这道题题意是 ,几个素数的几次幂相乘,求最小的幂。
比如108=4*27=22*33,min=2;
那先打一个素数表求出1-4000的素数个数,由于数有1018,
要是没除尽的话,因子最多也就4个了,所以幂数大于1的情况有p14,p13, p12 , p12*p22,
Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps=1e-5;
int P4 ( ll x )
{
    ll l=floor(pow( x, 1.0/4 )+eps);
    ll sum = l*l*l*l;
    return sum==x;
}
int P3 ( ll x )
{
    ll l=floor(pow( x, 1.0/3 )+eps);
    ll sum = l*l*l;
    return sum==x;
}
int P2 ( ll x )
{
    ll l=floor(pow( x, 1.0/2 )+eps);
    ll sum = l*l;
    return sum==x;
}
int isprime[4010];
int primes[4010],len;
void get_prime()
{
    len = 0;
    memset(isprime,true,sizeof(isprime));
    isprime[0] = false;
    isprime[1] = false;
    for( int i=2 ; i<4010 ; i++ )
    {
        if( isprime[i] )
            primes[len++] = i;
        for( int j=0 ; j<len ; j++ )
        {
            if( i*primes[j]>=4010 )
                break;
            isprime[i*primes[j]]=false;
            if( i%primes[j]==0 )
                break;
        }
    }
}

int main()
{
    get_prime();
    int repeat;
    cin>>repeat;
    while(repeat--)
    {
        ll n;
        cin>>n;
        int ans = 100;
        for( int i=0; i<len; i++ )
        {
            if(n<primes[i])
                break;
            if(n%primes[i]==0)
            {
                int tmp=0;
                while(n%primes[i]==0)
                {
                    n/= primes[i];
                    tmp++;
                }
                ans=min(ans,tmp);
            }
        }
        if( n==1 )
        {
            printf("%d\n",ans);
        }
        else
        {
            if(ans>4&&P4(n))
            {
                printf("4\n");
            }
            else if(ans>3&&P3(n))
            {
                printf("3\n");
            }
            else if(ans>2&&P2(n))
            {
                printf("2\n");
            }
            else
            {
                printf("1\n");
            }
        }
    }
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/192994.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 向量与矩阵范数_矩阵范数与谱半径的关系

    向量与矩阵范数_矩阵范数与谱半径的关系范数(norm),是具有“长度”概念的函数。在线性代数、泛函分析及相关的数学领域,范函是一个函数,其为矢量空间内的所有矢量赋予非零的正长度或大小。半范数反而可以为非零的矢量赋予零长度。举一个简单的例子,在二维的欧氏几何空间R就可定义欧氏范数。在这个矢量空间中的元素常常在笛卡儿坐标系统中被画成一个从原点出发的带有箭头的有向线段。每一个矢量的欧氏范数就是有向线段的长度。其中定义范数的矢量空间就是赋范矢

    2022年9月19日
    0
  • 怎么查看tomcat是否安装_如何查看申报是否成功

    怎么查看tomcat是否安装_如何查看申报是否成功Step1、下载软件安装包访问Apache官网,tomcat是开源组织Apache成员,我们可以在Apache官网中下载tomcat。下载网址:http://tomcat.apache.org/打开页面如下可以在当前这个页面选择自己想要下载的版本。Step2、下载后,直接解压,是免安装的包,进入Tomcat的安装路径bin目录下,我放的是本机的D盘,

    2022年9月19日
    0
  • Apache 模块 mod rewrite RewriteCond 通过检查HTTP REFERER避免

    Apache 模块 mod rewrite RewriteCond 通过检查HTTP REFERER避免Apache模块modrewriteRewriteCond通过检查HTTPREFERER避免

    2022年5月13日
    41
  • pythonrandom函数用法_python之random模块函数的使用

    pythonrandom函数用法_python之random模块函数的使用1)random.random()#用于生成一个0到1的随机浮点数,(0,1】2)random.randint(a,b)#用于生成一个指定范围内的整数,【a,b】3)random.randrange([start],stop[,step])#从指定范围内,按指定基数递增的集合中获取一个随机数。注意参数是整数,且不包括stop。random.randrange(10,30,2),结果相当…

    2022年5月13日
    63
  • offset宏定义_vba left函数

    offset宏定义_vba left函数最近做某项目撸代码时用到了offsetof宏,第一次使用这个宏,项目结束后对其用法也略知一二,现分享如下。位于stddef.h中的offsetof()宏,是获得struct中某成员相对于struct首地址的偏移量,以byte为单位,用struct首地址加该偏移量获得该成员的实际地址时,要把struct首地址强制转换成以byte为计数单位,地址本身一般都是32位(与芯片架构有关),强制转换的计数单位…

    2022年8月22日
    5
  • CLion 2021.5.3激活码(最新序列号破解)

    CLion 2021.5.3激活码(最新序列号破解),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月19日
    45

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号