-
Notifications
You must be signed in to change notification settings - Fork 0
/
10015.cpp
85 lines (69 loc) · 905 Bytes
/
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cmath>
bool prime(int key)
{
int a;
a=sqrt(key)+1;
if (key==1)
return 0;
for (int i=2;i<a;i++)
if (key%i==0)
return 0;
return 1;
}
main()
{
int n;
int position;
int *p;
int i;
int j;
int key;
int k;
int y;
while (1)
{
y=0;
position;
key=2;
cin>>n;
if (n==0) break;
p=new int[n];
for (i=0;i<n;i++)
p[i]=1;
for (i=1;i<n;i++)
{
while (1)
{
if (prime(key))
break;
key++;
}
j=0;
//cout<<key<<endl;
while (j<key)
{
//cout<<j;
if (p[y]!=0)
{
j++;
position=y;
}
y++;
if (y>n-1) y=0;
}
p[position]=0;
key++;
}
for (i=0;i<n;i++)
if (p[i]!=0)
{
cout<<i+1<<endl;
break;
}
}
return 0;
}