Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- //#include <cmath>
- //#include <iomanip>
- using namespace std;
- bool simple (int n)
- {
- int cnt = 0;
- for (int i = 2; i * i <= n; i++ )
- if (n % i == 0) cnt++;
- if (cnt == 0) return true;
- else return false;
- }
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- int a, b, cnt, ch1, ch2;
- in >> a;
- ch1 = 1;
- ch2 = 1;
- if (simple (a) == true)
- out << a;
- else
- {
- for (int i = a + 1; simple(i) != true; i++)
- ch2++;
- for (int i = a - 1; simple(i) != true; i--)
- ch1++;
- if (ch1 <= ch2) out << a - ch1;
- else out << a + ch2;
- }
- in.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement