-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1032.cpp
50 lines (39 loc) · 1 KB
/
1032.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
#include <bits/stdc++.h>
using namespace std;
bool isPrime(unsigned long long n) {
if (n == 2) return true;
if (n % 2 == 0) return false;
for (unsigned long long i = 3; i * i <= n; i += 2) {
if (n % i == 0) return false;
}
return true;
}
int main(){
unsigned long long n, conta=0, m=0;
vector <unsigned long long> v;
v.push_back(2);
for (unsigned long long i = 3; conta<= 3502; i+=2) {
if (isPrime(i)) {
v.push_back(i);
conta++;
}
}
cin >> n;
while(n!=0){
m=0;
vector <unsigned long long> numeros;
for(unsigned long long i = 0; i < n; i++){
numeros.push_back(i+1);
}
long long j = 0;
while(numeros.size() > 1){
m+=v[j]-1;
m = m%numeros.size();
numeros.erase(numeros.begin()+m);
j++;
}
cout<< numeros[0] << endl;
cin >> n;
numeros.clear();
}
}