I have debugged my program from all points of view but i cant find the cause of a wrong answer for this problem
http://uva.onlinejudge.org/external/4/406.html here is my source code for the problem #include<iostream> #include<cstdio> #include<cstdlib> #include<vector> #include<iostream> #include<algorithm> #include<cmath> #include<iterator> using namespace std; #define pb push_back vector<bool>prime; // this vector will hold all the primes inline int sieve() { int i,j; for(i = 0; i <= 1000 ; i++) prime.pb(true); for(i = 2; i*i <= 1000 ; i++) { for(j = 2 ; i*j <= prime.size() ; j++ ) prime[i*j] = false; } return 0; } int main() { int i,j,k; sieve(); int N,C; while( scanf("%d %d",&N,&C) == 2) { vector<int>primes; primes.pb(1); for(i=2;i<=N;i++) if(prime[i]) primes.pb(i); vector<int>::iterator p; // used for pointing to the vector printf("%d %d: ",N,C); if((primes.size())%2 == 0) { if(C*2 >= primes.size()) { for(i=0;i<primes.size();i++) printf("%d ",primes[i]); } else { p=primes.begin(); p=p+((primes.size() - (2*C))/2); for(i=0;i<(C*2);i++) printf("%d ",*(p+i)); } } else { if((C*2 - 1) >= primes.size() ) { for(i=0;i<primes.size();i++) printf("%d ",primes[i]); } else { p=primes.begin(); p = p + ((primes.size() - (2*C - 1))/2); for(i=0;i<(2*C-1);i++) printf("%d ",*(p+i)); } } printf("\n"); } getchar(); getchar(); return 0; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.