Time limit 1000 ms

Memory limit 65536 kB

OS Windows

中文题意

给一个数n,设将n质因数分解后可以得到

\[n=\prod_{i=1}^{\omega(n)} a_i^{p_i}
\]

其中\(\omega(n)\)意思是n的不同质因子个数,\(a_i\)是n的质因子。

要求输出最小的\(p_i\)。

题解

看完题解感觉很妙啊——

Let's first factorize \(N\) using prime numbers not larger than \(N^{\frac{1}{5}}\). And let's denote \(M\) as the left part, all the prime factors of \(M\) are larger than \(N^{\frac{1}{5}}\). If \(M=1\) then we are done, otherwise M can only be \(P^2\), \(P^3\), \(P^4\) or \(P^2 \times Q^2\), here \(P\) and \(Q\) are prime numbers.

  1. If \(M^{\frac{1}{4}}\) is an integer, we can know that \(M=P^4\). Update answer using 4 and return.
  2. If \(M^{\frac{1}{3}}\) is an integer, we can know that \(M=P^3\). Update answer using 3 and return.
  3. If \(M^{\frac{1}{2}}\) is an integer, we can know that \(M=P^2\) or \(M=P^2 \times Q^2\). No matter which situation, we can always update answer using 2 and return.
  4. If (1)(2)(3) are false, we can know that answer=1.

Since there are just \(O(\frac{N^{\frac{1}{5}}}{log(N)})\) prime numbers, so the expected running time is \(O(\frac{TN^{\frac{1}{5}}}{log(N)})\).

官方题解导致我一开始没反应过来的地方在于

M can only be \(P^2\), \(P^3\), \(P^4\) or \(P^2 \times Q^2\),

不是only,\(M\)还可以是\(PQRS\)、\(P^2QR\)、\(PQR\)、\(P^3Q\)、\(P^2Q\),之类的,而这些的答案都是1,也就是题解里编号4所说的,不是前三种情况。

另外一个问题,如何判断\(\sqrt[4]M\)、\(\sqrt[3]M\)、\(\sqrt{M}\)是否是整数呢?我们可以求出\(\sqrt[4]M\)、\(\sqrt[3]M\)、\(\sqrt{M}\)向下取整后的结果,再乘回去,比如,看看是否存在\(\lfloor\sqrt{M}\rfloor^2==M\)。

还有,求\(\lfloor\sqrt[3]{M}\rfloor\)时,pow函数精度不太够,用pow(n,1.0/3.0)会WA,要二分法求。下面这段二分法的代码来自这个博客代码里的two函数,要是有整数解就返回整数解,否则返回负一,这倒是挺好。

还有……复杂度那个log哪里来的?和质数分布有关?

源代码

#include<stdio.h>
#include<math.h>
#include<algorithm>
int T;
long long n;
long long cnt=0;
long long prime[10000];
long long ans;
bool vis[10000]; void shai()//取变量名一次回到解放前。还别说,挺方便的,一目了然
{
for(int i=2;i<=10000;i++)
{
if(!vis[i]) prime[++cnt]=i;
for(int j=1;j<=cnt&&i*prime[j]<=10000;j++)
{
vis[i*prime[j]]=1;
if(i%prime[j]==0)
break;
}
}
} long long sancigeng(long long a)
{
long long l=1,r=(long long)pow(n*1.0, 1.0 / 3) + 1,mid;
while(l<=r){
mid=(l+r)>>1;
if(mid*mid*mid==n) return mid;
else if(mid*mid*mid>n) r=mid-1;
else l=mid+1;
}
return -1;
} int main()
{
shai();
//freopen("test.in","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
ans=0x7fffffff;
int pw,pr;
for(int i=1;i<=cnt;i++)
{
if(n%prime[i]==0)
{
pr=prime[i],pw=0;
while(n%pr==0)
{
n/=pr;
pw++;
}
if(pw<ans) ans=pw;
}
if(ans==1)
{
n=1;
break;
}
}
if(n==1)
{
printf("%lld\n",ans);
continue;
}
long long temp1=sqrt(n),temp2=sqrt(temp1),temp3=sancigeng(n);
if(temp2*temp2==temp1&&temp1*temp1==n)
{//algorithm里的max和min不支持long long和int混杂的参数,居然不会隐式类型转换
ans=std::min(ans,4LL);
}
else if(temp3>=0)
{
ans=std::min(ans,3LL);
}
else if(temp1*temp1==n)
{
ans=std::min(ans,2LL);
}
else ans=1;
printf("%lld\n",ans);
}
return 0;
}

HDU 6623 Minimal Power of Prime的更多相关文章

  1. HDU 6623"Minimal Power of Prime"(数学)

    传送门 •题意 给你一个大于 1 的正整数 n: 它可以分解成不同的质因子的幂的乘积的形式,问这些质因子的幂中,最小的幂是多少. •题解 定义 $ans$ 表示最终答案: ①如果 $ans \ge 5 ...

  2. HDU 6623 Minimal Power of Prime(数学)

    传送门 •题意 给你一个大于 1 的正整数 n: 它可以分解成不同的质因子的幂的乘积的形式,问这些质因子的幂中,最小的幂是多少. •题解 把[1,10000]内的素数筛出来,然后对于每个素$P$数遍历 ...

  3. HDU 6623 Minimal Power of Prime(思维)题解

    题意: 已知任意大于\(1\)的整数\(a = p_1^{q_1}p_2^{q_2} \cdots p_k^{q_k}\),现给出\(a \in [2,1e18]\),求\(min\{q_i\},q ...

  4. 2019杭电多校第四场hdu6623 Minimal Power of Prime

    Minimal Power of Prime 题目传送门 解题思路 先打\(N^\frac{1}{5}\)内的素数表,对于每一个n,先分解\(N^\frac{1}{5}\)范围内的素数,分解完后n变为 ...

  5. [2019杭电多校第四场][hdu6623]Minimal Power of Prime

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6623 题目大意为求一个数的唯一分解的最小幂次.即120=23*31*51则答案为1. 因为数字太大不能 ...

  6. 2019 Multi-University Training Contest 4 - 1010 - Minimal Power of Prime

    http://acm.hdu.edu.cn/showproblem.php?pid=6623 题意,给50000个1e18级别的数N,求它质因数分解里面的最小的指数(不算0) 比赛的时候给划了一个1e ...

  7. 2019HDU多校Minimal Power of Prime——分段讨论&&思维

    题目 将 $n$($1 < n \leq 10^{18}$)质因数分解,求质因数幂的最小值. 分析 直接质因数分解,不太行. 可以这样想,对小区间质因数分解,n变小了,再枚举答案. 打印1-10 ...

  8. 2019hdu多校 Minimal Power of Prime

    题目链接:Click here 题目大意:求一个数分解质因数后的最小幂指数 Solution: 首先,我们肯定是不能直接暴力求解的 我们先考虑筛出1e4范围以内的所有质数,把x所有这个范围内的质因子筛 ...

  9. 【HDOJ6623】Minimal Power of Prime(Powerful Number)

    题意:给定大整数n,求其质因数分解的最小质数幂 n<=1e18 思路:常规分解算法肯定不行 考虑答案大于1的情况只有3种:质数的完全平方,质数的完全立方,以及p^2*q^3,p,q>=1三 ...

随机推荐

  1. Java回调机制的理解

    用一句话讲明回调机制就是,在A类里面拥有一个类B的对象,调用B类的某个方法并把自身引用传入,在B类的这个方法里面又通过传进来的A的引用来调用A类的某个方法(这个最后调用的A类的方法就叫做回调方法). ...

  2. 【组策略】1.组策略介绍group policy

    组策略介绍group policy 高效学习法,念念不忘,必有回响. 分享一个高效学习思维,潜意识思考.就是在您没有大量时间的情况下,学习十分钟. 然后离开去完成别的事情的时候,大脑潜意识中还会继续思 ...

  3. 20191128 Spring Boot官方文档学习(9.11-9.17)

    9.11.消息传递 Spring Boot提供了许多包含消息传递的启动器.本部分回答了将消息与Spring Boot一起使用所引起的问题. 9.11.1.禁用事务JMS会话 如果您的JMS代理不支持事 ...

  4. itchat监听微信撤回消息

    import itchat from itchat.content import * import re msg_infomation = {} # 监听发送消息 @itchat.msg_regist ...

  5. Java8---函数式编程-示例

    // Java8函数式编程示例—(Predicate.Stream.Optional) https://blog.csdn.net/weixin_41950473/article/details/84 ...

  6. spring-第N篇整合SSM,即Mybatis+Spring+Spring MVC

    1.Mybatis的配置使用 1>Jar包:mybatis-3.4.5.jar.mysql-connector-6.0.2或者ojdbc6-11.2.0.4.jar. 2>编写conf.x ...

  7. [2019上海网络赛F题]Rhyme scheme

    题目链接 题意,求出合法的长度为n的字典序第k小字符串,合法的定义为除了最后一位,每一位的取值范围为'A'到'A'+pos-1,而最后一位的取值范围'A'到当前字符串最大值+1. 队友tql,Orz ...

  8. Pycharm2019.1.3破解

    搬运: T3ACKYHDVF-eyJsaWNlbnNlSWQiOiJUM0FDS1lIRFZGIiwibGljZW5zZWVOYW1lIjoi5bCP6bifIOeoi+W6j+WRmCIsImFzc ...

  9. sublime3跳转函数

    点击Preferences->Browse Packages进入Packages目录,然后打开User目录,查看User目录里面有没有Default (Windows).sublime-mous ...

  10. XIB约束布局问题(通过优先级改变界面布局)

    需要注意的是,只能修改可选约束的优先级,也就是说: 不允许将优先级由小于1000的值改为1000 不允许将优先级由1000修改为小于1000的值 例如,如果将优先级由250修改为1000,则会抛出异常 ...