-
Notifications
You must be signed in to change notification settings - Fork 14
/
10015.cpp
69 lines (64 loc) · 1.25 KB
/
10015.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
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define FOI(i, A, B) for(i=A; i<=B; i++)
#define FOD(i, A, B) for(i=A; i>=B; i--)
#define MAX 100000
bool isP[MAX + 1];
vector<int> Prime;
void seive(){
memset(isP, true, sizeof isP);
isP[0] = false; isP[1] = false;
for (int i = 2; i <= MAX; i++){
if (isP[i]){
Prime.push_back(i);
for (int j = 2 * i; j <= MAX; j += i)
isP[j] = false;
}
}
//cout << Prime.size() << endl;
}
int main(){
//freopen("testI.txt", "r", stdin);
//freopen("testO.txt", "w", stdout);
seive();
while (true){
int N, i;
scanf("%d", &N);
if (N == 0) break;
vector<int> V(N);
FOI(i, 0, N-1)
V[i] = i + 1;
int pos = 0;
FOI(i, 0, N-2){
pos = (pos + Prime[i] - 1) % V.size();
//cout << Prime[i] << " " << pos << endl;
V.erase(V.begin() + pos);
}
printf("%d\n", V[0]);
}
return 0;
}