AtCoder Beginner Contest 169 比赛人数11374 比赛开始后15分钟看到A题,在比赛开始后第20分钟看到所有题
AtCoder Beginner Contest 169 D Div Game 质因数分解+幂次分解为连续整数+当心溢出
总目录详见https://blog.csdn.net/mrcrack/article/details/104454762
在线测评地址https://atcoder.jp/contests/abc169/tasks/abc169_d
样例模拟如下
24=2^3*3^1
2^3中的幂次3=1+2可以分解2次
3^1中的幂次1=1可以分解1次
总的可以分解2+1=3次
64=2^6
2^6中的幂次6=1+2+3可以分解3次
总的可以分解3次
AC代码如下
#include <stdio.h>
#define LL long long
int p[50],m[50],tot;//p[]记录质数,m[]记录幂次
int main(){
LL n;
int i,j,ans=0;
scanf("%lld",&n);
for(i=2;(LL)i*i<=n;i++)//注意此处不能写成for(i=2;i*i<=n;i++)
if(n%i==0){
p[++tot]=i;
while(n%i==0)n/=i,m[tot]++;
}
if(n>1)p[++tot]=n,m[tot]=1;
for(i=1;i<=tot;i++){
j=1;
while(1){
if(m[i]>=j)ans++,m[i]-=j;
else break;
j++;
}
}
printf("%d\n",ans);
return 0;
}