x2311

Untitled

Nov 14th, 2021
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. //проверяю если число простым
  5. bool primeNumber(int j){
  6.     for(int i=2;i<j;i++){
  7.         if(j%i==0){
  8.             return false;
  9.         }
  10.     }
  11.     return true;
  12. }
  13.  
  14. //просто смотрю если числа близнеци или же нет
  15. bool checkForTwinNumbers(int i){
  16.     int e=0;
  17.     for(int j = i-1; j < 2 * i; j++){
  18.         if((e+2)==j && primeNumber(j)){
  19.             return true;
  20.         }
  21.         if(primeNumber(j)){
  22.             e=j;
  23.         }
  24.     }
  25.     return false;
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.     //введите число
  32.     cout<<"Enter the number: ";
  33.     int i;
  34.     cin >> i;
  35.    
  36.     if(checkForTwinNumbers(i)){
  37.         //Есть простые числа близнецы
  38.         cout << "There are twin primes";
  39.     }else{
  40.         //Нет простых числ близнецов
  41.         cout << "There are no twin primes";
  42.     }
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment