fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool nt(long long n) {
  5. if (n <= 1) return false;
  6. if (n == 2 || n == 3) return true;
  7. if (n % 2 == 0 || n % 3 == 0) return false;
  8. for (long long i = 5; i * i <= n; i += 6) {
  9. if (n % i == 0 || n % (i + 2) == 0) return false;
  10. }
  11. return true;
  12. }
  13.  
  14. int main() {
  15. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  16. long long a, b; cin >> a >> b;
  17. long long c = a - b;
  18. if (c != 1) {
  19. cout << "NO\n";
  20. return 0;
  21. }
  22. long long n = a * a - b * b;
  23. cout << (nt(n) ? "YES\n" : "NO\n");
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
NO