-
Notifications
You must be signed in to change notification settings - Fork 0
/
drStrange.cpp
executable file
·80 lines (68 loc) · 1.27 KB
/
drStrange.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> makeSieve(int n){
vector<int> v;
// vector<int> iterator i;
// for(i =v.begin();i!=v.end();i++){
// }
for(int i=0;i<=n;i++){
v.push_back(i);
}
for(int i=n;i>=2;i--){
if(v.at(i)==i){
int k =i;
k = k+i;
while(k<=n){
v[k] = i;
k= k+i;
}
}
}
return v;
}
void printStrange(vector<int> v,int n){
bool *arr = new bool[n+1];
//cout<<"okk";
vector<int> result;
//vector<int> primes;
for(int i=n;i>=1;i--){
//cout<<endl;
//cout<<"*"<<i<<"*"<<arr[i]<<endl;
if(arr[i]==false){
//cout<<endl;
int x = i;
while(x!=1){
int lpd = v.at(x);
//cout<<lpd<<endl;
int k=i;
while(k>=lpd){
if(arr[k]==false){
result.push_back(k);
arr[k] = true;
//cout<<k<<"false";
}
k = k-lpd;
}
while(x%lpd==0){
x=x/lpd;
}
}
}
sort(result.begin(),result.end(),greater<int>());
vector<int>::iterator it = v.begin();
for (it = result.begin();it!=result.end(); it++){
cout<<*it<<" ";
}
result.clear();
}
cout<<"1";
}
int main(){
int n;
cin>>n;
vector<int> v = makeSieve(n);
printStrange(v,n);
return 0;
}