1 seconds
Memory limit:32 MB
Special question: No
submitted:4466
Resolution:1375
-
Title Description:
The
-
number of the mass factor for a positive integer N (n>1). The same quality factor requires repeated calculations. such as 120=2*2*2*3*5, a total of 5 qualitative factors.
-
Input:
-
There may be multiple sets of test data, and the input to each set of test data is a positive integer N, (1<n<10^9).
-
Output:
-
For each set of data, the number of the quality factor of the output n.
-
Sample input:
-
120
-
Sample output:
-
5
-
Tips:
-
Note: 1 is not a mass factor of N; n is the mass factor of N if n is a prime number.
-
Source:
- 2007, Tsinghua University computer Research Life Test real problem
If all the factors in the test 2 to 100000 are not decomposed to 1, a also has a factor greater than 100000 ans++; Solution 1:
#include <stdio.h> #define M 100000int prime[m];int flag[m];int cnt;void getprime () { cnt=1; for (int i=2;i<m;++i) { if (!flag[i]) { prime[cnt++]=i; for (int j=i;j<m;j+=i) flag[j]=1;}} } int main (int argc, char *argv[]) { //freopen ("1207.in", "R", stdin); int num; Getprime (); while (scanf ("%d", &num)!=eof) { int ans=0; int i; for (I=1;i<cnt;++i) { while (num%prime[i]==0) { ans++; Num/=prime[i]; } if (num==1) break; } if (i==cnt) ans++; printf ("%d\n", ans); } return 0;}
Solution 2:
#include <iostream> #include <stdio.h>using namespace std;int main (int argc, char *argv[]) { int num; Freopen ("1207.in", "R", stdin); while (scanf ("%d", &num)!=eof) { int ans=0; int i=2; int n=num; while (i*i<=n) { if (num%i==0) { num/=i; ans++; } else i++; } if (num!=1) ans++; printf ("%d\n", ans); } return 0;}
Time Comparison--
Solution One:
Solution Two:
I don't see the difference.
Nine degrees OJ 1207 mass factor number (sieve prime, barely AC)