-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMysterious_Series.cpp
More file actions
58 lines (52 loc) · 1.01 KB
/
Mysterious_Series.cpp
File metadata and controls
58 lines (52 loc) · 1.01 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
/*
Ishaan is an adventurous guy. Today while wandering in a forest he found a cave. Bravely enough he enters the cave and finds some numbers carved on the walls of the cave which seemed to form a mysterious series.
But some of the numbers were missing. Now, Ishaan wants to complete the series. Help him find the Nth term of the series.
N Nth term
1 5
2 10
3 26
4 50
5 122
.
.
.
10 842
*/
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int x){
if(x == 1 || x == 0)
return false;
for(int i = 2; i<=sqrt(x); i++){
if(x%i==0){
return false;
}
}
return true;
}
void nthPrime(int n){
int count = 0, j = 2;
while(1){
if(isPrime(j)){
count++;
}
if(count==n){
break;
}
j++;
}
// cout<<j<<endl;
unsigned int result = j*j+1;
cout<<result<<endl;
}
int main() {
//code
int t;
cin>>t;
while(t-->0){
int n;
cin>>n;
nthPrime(n);
}
return 0;
}