fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define omen ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  4. #define ll long long
  5.  
  6. bool isPrime(int num) {
  7. for (int i = 2; i <= sqrt(num); i++) {
  8. if (num % i == 0) return false;
  9. }
  10. return true;
  11. }
  12.  
  13. int nextPrime(int n) {
  14. int current = n + 1;
  15. while (true) {
  16. if (isPrime(current)) return current;
  17. else current++;
  18. }
  19. }
  20.  
  21. int main() {
  22. omen;
  23. int n, m;cin >> n >> m;
  24. if (isPrime(m) && nextPrime(n) == m) cout << "YES" << endl; else cout << "NO" << endl;
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5268KB
stdin
7 11
stdout
YES