Created
October 25, 2022 01:06
-
-
Save kawaii-ghost/92727b7a562891fda7d3681a40253055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Online C++ compiler to run C++ program online | |
#include <cstdio> | |
#include <vector> | |
#include <inttypes.h> | |
#include <cstdbool> | |
using std::vector; | |
int_fast32_t prime(int_fast32_t num_k, vector<int_fast32_t> &arr); | |
int main() | |
{ | |
// Write C++ code here | |
std::vector<int_fast32_t> pri= {2, 3, 5, 7}; | |
uint_fast16_t t; | |
scanf("%" SCNuFAST16, &t); | |
getchar(); | |
for (int i = 0; i < t; i++) { | |
int_fast32_t k; | |
scanf("%" SCNdFAST32, &k); | |
getchar(); | |
k -= 1; | |
if (k > pri.size()) { | |
prime(k, pri); | |
} | |
printf("%" PRIdFAST32 "\n", pri[k]); | |
} | |
return 0; | |
} | |
int_fast32_t prime(int_fast32_t num_k, vector<int_fast32_t> &arr) | |
{ | |
for (int_fast32_t member = arr[arr.size() - 1]; num_k >= arr.size(); member += 2) { | |
bool yes = true; | |
for (int_fast32_t n: arr) { | |
if (!(member % n)) { | |
bool yes = false; | |
} | |
} | |
if (yes) | |
arr.push_back(member); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment