-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAMR11E.cpp
More file actions
76 lines (71 loc) · 1.36 KB
/
AMR11E.cpp
File metadata and controls
76 lines (71 loc) · 1.36 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <cstdio>
#include<cmath>
#define max 4000
using namespace std;
int arr[max]={0};
int a[1000]={0};
int cntr=0;
void sieve(){
int i,j;
for(i=2;i<(max);++i)
{
if(arr[i]>0)continue;
for(j=2*i;j<max;j+=i){
arr[j]++;
if(arr[j]>=3){
a[cntr]=j;
cntr++;
}
}
}
}
void merge(int [],int,int,int);
void mergeSort(int arr[],int low, int high){
if(low>=high)return;
int mid=(low+high)/2;
mergeSort(arr,low,mid);
mergeSort(arr,mid+1,high);
merge(arr,low,mid,high);
}
void merge(int arr[], int low, int mid, int high){
int a[high-low+1];
int i = low;
int j = mid+1;
int k = 0;
while(i<=mid && j<=high){
if(arr[i]>arr[j]){
a[k]=arr[j];
j++;
}
else{
a[k]=arr[i];
i++;
}
k++;
}
while(i<=mid){
a[k]=arr[i];
k++;i++;
}
while(j<=high){
a[k]=arr[j];
k++;j++;
}
int p=0;
for(int m=low;m<=high;m++,p++){
arr[m]=a[p];
}
}
int main() {
int t;
sieve();
mergeSort(a,0,cntr-1);
long int n;
scanf("%d",&t);
while(t--)
{
scanf("%ld",&n);
printf("%d\n",a[n-1]);
}
return 0;
}