Step Up

After completing his studies Jugnu joined a software company. his office in a huge multi-story building. today he is late for his office and there is no lift for going up.

Jugnu is tall, he has to step up in a building having N number of steps. The steps are numbered as 1 to N. he is at the Xth step and he has to reach the Yth step.

He doesn't like a prime number so he is going to skip the prime steps.

You are going to find which steps having his footprint and count of the footprint.

Example:

Input:  x = 2, y = 10

Output:

4 6 8 9 10 5

Approach:

C++

#include <bits/stdc++.h>
using namespace std;

bool prime[10001];
void primeInitialize()
{

    memset(primetruesizeof(prime));
    prime[0] = false;
    prime[1] = false;
    for (int i = 2i * i <= 10000i++)
    {
        if (prime[i])
        {
            for (int j = i * ij <= 10000j += i)
                prime[j] = false;
        }
    }
}

int stepUP(int xint y)
{
    int cnt = 0;
    for (int i = xi <= yi++)
    {
        if (prime[i] == false)
        {
            cout << i << "\n";
            cnt++;
        }
    }
    return cnt;
}
int main()
{

    int x = 2y = 10;

    primeInitialize();

    cout << stepUP(xy<< "\n";

    return 0;
}


No comments:

Post a Comment