HII GUYS this is also one of the easy problem
here simply apply the brute force logic
but just do that in precompute
i think there is no need to explain in this
if still u have doubt u can go through my solution
HERE is my ac c++ solution is::::
here simply apply the brute force logic
but just do that in precompute
i think there is no need to explain in this
if still u have doubt u can go through my solution
HERE is my ac c++ solution is::::
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 | #include<bits/stdc++.h> using namespace std; #define lim 50000 vector<int>dev; vector<bool>check(lim,false); void pre() { int i,j; for(i=2;i<=34000;i++) { if(check[i]==false) { int x=0; for(j=i+1;j<=34000;j++) { if(check[j]==false) x++; if(x==i) { check[j]=true; x=0; } } } } for(i=2;i<=34000;i++) { if(check[i]==false) { dev.push_back(i); } } //printf("%d",dev.size()); } int main() { pre(); while(1) { int n; scanf("%d",&n); if(n==0) break; printf("%d\n",dev[n-1]); } } |
1 comment:
this program is taking time 0.11 ........
but i reduce this to 0.0 by just storing my answer in an array bcz here value of n is atmost 3000 so u can simply store
ur that solution just become o(testcases)
Post a Comment