forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path355.cpp
More file actions
56 lines (51 loc) · 1.03 KB
/
355.cpp
File metadata and controls
56 lines (51 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
using namespace std;
int plist[10000],pcount=0;
int prime(int n){
int i;
if ((n!=2&&!(n%2))||(n!=3&&!(n%3))||(n!=5&&!(n%5))||(n!=7&&!(n%7)))
return 0;
for (i=0;plist[i]*plist[i]<=n;i++)
if (!(n%plist[i]))
return 0;
return n>1;
}
void initprime(){
int i;
for (plist[pcount++]=2,i=3;i<10050;i++)
if (prime(i))
plist[pcount++]=i;
}
int mm[10005];
int main() {
initprime();
int num;
cin >> num;
mm[1] = 1;
int m = 1;
for (int i = 2; i <= num; ++i) {
int n = i;
int c = 0;
for (int j = 0; j < pcount; ++j) {
int p = plist[j];
if (p * p > n) {
if (n != 1) ++c;
break;
}
while (n % p == 0) {
++c;
n /= p;
}
}
m = max(m, c + 1);
mm[i] = c + 1;
}
cout << m << endl;
for (int i = 1; i <= num; ++i) {
if (i != 1) cout << " ";
cout << mm[i];
}
cout << endl;
return 0;
}