题意:
思路:
直接o(sqrt(n))求因子的个数,结束的标志就是遇到了素数,因为素数的因子只有两个
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=1e5+50;
const int inf=0x3f3f3f3f;
ll gg(ll x){//求因子个数
ll ans=0;
for(ll i=1;i*i<=x;i++){
if(x%i==0){
if(i*i!=x)ans+=2;
else ans++;
}
}
return ans;
}
int pp(ll x){//判断素数
int flag=1;
for(int i=2;i*i<=x;i++){
if(x%i==0){
flag=0;
break;
}
}
return flag;
}
int main()
{
ll n;
scanf("%lld",&n);
ll ans=1;
while(!pp(n)){
n=gg(n);
ans++;
}
printf("%lld\n",ans);
return 0;
}
出题人代码:
写的更简单一点
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll f(ll x){ //求x的因子个数
ll i,res=0;
for(i=1;i*i<x;i++){
if(x%i==0)res+=2;
}
return res+(i*i==x);
}
int main(){
ll i=0,n;
cin>>n;
while(n!=2)n=f(n),i++;
cout<<i;
}
来源:CSDN
作者:_Alexander
链接:https://blog.csdn.net/weixin_44091178/article/details/104174663