题目:https://www.nowcoder.com/pat/2/problem/264
1 #include<iostream> 2 #include<algorithm> 3 #include<string.h> 4 #include<stdio.h> 5 using namespace std; 6 int prime[100005]; 7 //素数表 8 void prime_table() 9 { 10 int i, j; 11 for (i = 2; i<100005; i++) 12 if (prime[i] == 0) 13 for (j = 2 * i; j<100005; j += i) 14 prime[j] = 1; 15 } 16 17 int main() 18 { 19 int n, t = 0; 20 int a[20000]; 21 prime_table(); 22 for (int i = 2; i<100005; i++) 23 if (prime[i] == 0) 24 { 25 a[t] = i; 26 t++; 27 } 28 while (~scanf("%d", &n)) 29 { 30 int cnt = 0, i = 0; 31 while (n != 1) 32 { 33 if (n%a[i] != 0) 34 i++; 35 else if (n%a[i] == 0) 36 { 37 while (n%a[i] == 0) 38 n /= a[i]; 39 cnt++; 40 } 41 } 42 printf("%d ", cnt); 43 } 44 return 0; 45 }