Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //проверяю если число простым
- bool primeNumber(int j){
- for(int i=2;i<j;i++){
- if(j%i==0){
- return false;
- }
- }
- return true;
- }
- //просто смотрю если числа близнеци или же нет
- bool checkForTwinNumbers(int i){
- int e=0;
- for(int j = i-1; j < 2 * i; j++){
- if((e+2)==j && primeNumber(j)){
- return true;
- }
- if(primeNumber(j)){
- e=j;
- }
- }
- return false;
- }
- int main()
- {
- //введите число
- cout<<"Enter the number: ";
- int i;
- cin >> i;
- if(checkForTwinNumbers(i)){
- //Есть простые числа близнецы
- cout << "There are twin primes";
- }else{
- //Нет простых числ близнецов
- cout << "There are no twin primes";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment