题目类型:数论、分解质因数
思路
依次枚举i是否是n的质数约数即可(也就是求n的质因数有几个)
注意:本题答案可能会爆int,所以开long long
正解代码
#include<bits/stdc++.h> //万能头文件
using namespace std;
typedef long long LL; //结果可能会爆int,所以开long long
int main()
{
LL n;
cin>>n;
LL res=0;
for(LL i=2;i<=n/i;i++) //循环根号n次
{
if(n%i==0) //如果i是n的约数
{
res++;
while(n%i==0)
n/=i;
}
}
if(n>1)
res++;
cout<<res;
return 0; //好习惯
}