Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lucky Numbers.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- void WaitLine()
- {
- using namespace std;
- cin.clear();
- cin.ignore(255, '\n');
- cin.get();
- }
- int main()
- {
- using namespace std;
- int Max = 10004;
- bool NumberList[10004]; //Declare our list.
- //Initialise all elements to true.
- for (int i = 0; i < Max; i++)
- {
- NumberList[i] = true;
- }
- //Falsify all evens (including 0)
- for (int i = 0; i < Max; i++)
- {
- if (i % 2 == 0)
- {
- NumberList[i] = false;
- }
- }
- //Consistent variable declarations
- int nMod = -1;
- //Main program logic.
- for (int i = 3; i < Max; i++)
- {
- if (NumberList[i])
- {
- nMod = i - 1;
- for (int j = 1; j < Max; j++)
- {
- if (NumberList[j])
- {
- if (nMod == 0)
- {
- NumberList[j] = false;
- nMod = i - 1;
- }
- else
- {
- nMod--;
- }
- }
- }
- }
- }
- //Output logic
- int SearchVal = -1;
- int Below = -1, Above = -1;
- cin >> SearchVal;
- int k = 0;
- do
- {
- if (NumberList[k])
- {
- if (k > SearchVal)
- {
- Above = k;
- }
- else if (k < SearchVal)
- {
- Below = k;
- }
- }
- k++;
- } while(Above < SearchVal);
- cout << Below << " " << Above;
- WaitLine();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement