Prime Factors-素数

来源:互联网 发布:外国人淘宝开店 编辑:程序博客网 时间:2024/05/16 04:41

问题 J: Prime Factors

时间限制: 1 Sec  内存限制: 32 MB
提交: 23  解决: 18
[提交][状态][讨论版]

题目描述

I'll give you a number , please tell me how many different prime factors in this number.

输入

There is multiple test cases , in each test case there is only one line contains a number N(2<=N<=100000). Process to the end of file.

输出

For each test case , output one line contains one number , indicating different prime factor in the number N.

样例输入

12530

样例输出

2
13

#include <stdio.h>#include <math.h>#define N 100010int Prime[N];void pri(){Prime[1]=false;Prime[2]=true;for(int i=3; i<=N; i++){if(i%2)Prime[i]=true;elsePrime[i]=false;}int t=sqrt(N);for(int i=3; i<=t; i++){if(Prime[i])for(int j=2*i; j<=N; j+=i)Prime[j]=false;}}int main(){int q, i, n, count;pri();while(scanf("%d", &n)!=EOF){count=0;q=n/2;if(Prime[n]){printf("1\n");continue;}for(i=1; i<=q; i++){if(Prime[i]&&n%i==0){while(n%i==0)n/=i;count++;}}printf("%d\n",count);}}


0 0
原创粉丝点击