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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • log4j自定义layout_log4j使用教程

    log4j自定义layout_log4j使用教程如果使用pattern布局就要指定的打印信息的具体格式ConversionPattern,打印参数如下:   %m输出代码中指定的消息    %p输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL    %r输出自应用启动到输出该log信息耗费的毫秒数    %c输出所属的类目,通常就是所在类的全名    %t输出产生该日志事件的线

    2022年8月22日
    11
  • CentOS安装MySQL8.0「建议收藏」

    CentOS安装MySQL8.0「建议收藏」目录配置yum源wget下载源安装包安装源安装MySQL启动相关启动服务查看启动状态设置开机自启重启服务配置修改密码卸载卸载MySQL删除文件配置yum源wget下载源安装包如果没有安装wget,先安装yum-yinstallwget进入mysql官网下载:https://dev.mysql.com/downloads/repo/yum/复制下载链接:https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rp

    2022年6月26日
    25
  • putty 与winscp 区别

    putty 与winscp 区别

    2021年10月8日
    50
  • windows7下预览psd

    windows7下预览psdPhotoshopcs5安装完后电脑里PSD格式的文件无法显示缩略图,想看原图必须打开软件才能知道图片的内容,安装此补丁之后不用打开软件,在文件夹里就可以看到PSD格式图片的内容,挺方便的,本人亲自测试可以在win7下使用。使用方法:将"psicon.dll"文件拷备到系统system32目录下,不然的话重启之后又看不到缩略图了。步骤一:解压到任何文件夹;步骤二:将psicon.dll拷备到…

    2022年6月11日
    32
  • idea19版1.4激活码为啥一直报错【在线破解激活】

    idea19版1.4激活码为啥一直报错【在线破解激活】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月17日
    53
  • DataGrid中DropDownList的动态绑定和触发DropDownList事件[通俗易懂]

    DataGrid中DropDownList的动态绑定和触发DropDownList事件[通俗易懂]我在写DataGrid控件中子控件事件时候,DropDownList的事件相比而言麻烦一点,在此,我简单罗列如下(我在此处为了方便这里都用DataGrid中的隐藏列存储我所要的数据):一、DropDownList的动态绑定,只需在DataGrid1_ItemDataBound的事件中,取出数值进行匹配,便可以了,具体代码如下:二、触发DataGrid中DropDownList的事件前台

    2022年9月12日
    3

发表回复

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

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