返回顶部

蓝桥杯质因数个数

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long int LL;
const LL maxn=100010;
LL prime[maxn];
bool p[maxn]={false};
LL p_num=0;
void gen_prime()
{
  for(LL i=2;i<maxn;i++)
  {
    if(p[i]==false)
    {
      prime[p_num++]=i;
      for(int j=i+i;j<maxn;j+=i)
      {
        p[j]=true;
      }
    }
  }
}

int main()
{
  
    LL n;
    gen_prime();
    for(int i=0;i<10;i++)
    {
      cout<<prime[i]<<" ";
    }
   scanf("%lld",&n);
  int pNum=0;
  int count=0;
  while(prime[pNum]<n)
  {
    if((n%prime[pNum])==0)
    {
     
      count++;
      pNum++;
    }
    else
    {
      pNum++;
      continue;
    }
  }
  cout<<count++;
  system("pause");
 

  return 0;
  
} 

  

posted @ 2022-04-09 12:18  tianyudizhua  阅读(72)  评论(0编辑  收藏  举报