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)
上一篇 2025年12月4日 上午9:43
下一篇 2025年12月4日 上午10:15


相关推荐

  • List如何去除重复元素

    List如何去除重复元素1 方法一 publicstatic Listlist for inti 0 i list size 1 i for intj list size 1 j i j if list get list size 1 i for intj list size 1 j

    2026年3月18日
    2
  • 系统web服务器配置,简单介绍Web服务器的配置方法

    系统web服务器配置,简单介绍Web服务器的配置方法关于 Web 服务器的配置方法如果不说的具体一些的话 恐怕一些不是高手的用户就会比较难懂 因此本教程就结合实例给大家说说吧 近日 笔者将学校服务器的操作系统升级为 WindowsServe 在 Web 服务器的配置过程中发现了许多与 windows2000S 的不同之处 为了同行少走弯路 现将配置中应注意的问题简单总结如下 WindowsServe 中 Internet

    2026年3月18日
    1
  • 如何用DeepSeek生成Logo设计:保姆级教程来了!

    如何用DeepSeek生成Logo设计:保姆级教程来了!

    2026年3月16日
    3
  • CSDN博客积分计算规则

    CSDN博客积分计算规则CSDN 博客积分计算规则 1 每公布一篇原创或者翻译文章 可获得 10 分 2 每公布一篇转载文章 可获得 2 分 3 博主的文章每被评论一次 可获得 1 分 4 每发表一次评论 可获得 1 分 自己给自己评论 博主回复别人对自己博文的评论不获得积分 5 博文阅读次数每超过 100 次 可获得 1 分 阅读加分最高加到 100 分 即文章点击上万次截止 6 文章被投票 顶 1 票加 1 分 踩 1 票减 1 分

    2026年3月19日
    2
  • 随机森林(原理/样例实现/参数调优)

    决策树决策树与随机森林都属于机器学习中监督学习的范畴,主要用于分类问题。决策树算法有这几种:ID3、C4.5、CART,基于决策树的算法有bagging、随机森林、GBDT等。决策树是一种利用树形结构进行决策的算法,对于样本数据根据已知条件或叫特征进行分叉,最终建立一棵树,树的叶子结节标识最终决策。新来的数据便可以根据这棵树进行判断。随机森林是一种通过多棵决策树进行优化决策的算法。案例:

    2022年4月9日
    142
  • LeetCode——Pascal&#39;s Triangle

    LeetCode——Pascal&#39;s Triangle

    2022年1月5日
    45

发表回复

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

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