Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <math.h>
- using namespace std;
- int main() {
- vector<short int> v;
- int bogdan;
- int tab[10000];
- tab[0]=2;
- tab[1]=3;
- int it=2;
- for (int i=2; it<=10000; i++)
- for (int j=2; j*j<=i; j++)
- {
- if (i % j == 0)
- break;
- else if (j+1 > sqrt((float)i)) {
- //cout << i << ' ';
- tab[it]=i;
- it++;
- }
- }
- int n, m;
- cin >> n;
- for(int testy=0; testy<n; testy++){
- cin >> m;
- v.clear();
- for(int i=1; i<=m; i++){
- v.push_back(i);
- }
- bogdan=0;
- for(int i=0; i<m-1; i++){
- bogdan+=tab[i];
- bogdan=bogdan%v.size();
- if(bogdan==0)
- v.erase(v.begin()+v.size()-1);
- else{
- v.erase(v.begin()+bogdan-1);
- bogdan--;
- }
- }
- cout << v.at(0) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement