## Uva 406 Why I get Wrong Answer

Moderator: Board moderators

Ar Anik
New poster
Posts: 2
Joined: Sun Feb 24, 2019 1:36 pm

### Uva 406 Why I get Wrong Answer

#include<bits/stdc++.h>
using namespace std;
#define N 2000
int p[N+1];
vector<int>a;
void prime()
{
int i, j, l;
l = sqrt(N);
p = 1;
a.push_back(1);
a.push_back(2);
for(i=4; i<=N; i+=2)
p = 1;
for(i=3; i<=N; i+=2)
{
if(p == 0)
{
a.push_back(i);
if(i<=l)
{
for(j=i*i; j<=N; j+=i*2)
p[j] = 1;
}
}
}

}
int main()
{
prime();
int n, i, c, m, b, d, e;
while(cin >> n >> c)
{
b = 0;
if(n < c || n == c || n < 2*c)
{
cout << n << " " << c << ":";
for(i=0; a <= n; i++)
{
if(a != 0)
cout << " " << a;
}
cout << endl << endl;
continue;
}
for(i=0; a <= n; i++)
{
if(a != 0)
b++;
}
m = b/2;
cout << n << " " << c << ":";
if(b %2 == 0)
{
e = (2*c)/2;
for(i=m-e; i<=m+e-1; i++)
{
if(a <= n && a >0)
cout << " " << a;
}
}
else if(b %2 != 0)
{
e = 2*c-1-1;
d = e/2;
for(i=m-d; i<=m+d; i++)
{
if(a[i] <= n && a[i] > 0)
cout << " " << a[i];
}
}
cout << endl << endl;
}

return 0;
}