# C++ code to find number to disprove given prime hypothesis

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

Best Seller

66 Lectures 5.5 hours

Suppose we have a number n. Let there is a hypothesis "There exists a positive integer n that for each positive integer m number (n·m + 1) is a prime number". We have to find such m as a counter example to disprove this statement.

So, if the input is like n = 12, then the output will be 10, because 12*10 + 1 = 121 which is not prime.

## Steps

To solve this, we will follow these steps −

if n < 3, then:
return n + 2
Otherwise
return n - 2

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h>
using namespace std;
int solve(int n){
if (n < 3)
return n + 2;
else
return n - 2;
}
int main(){
int n = 12;
cout << solve(n) << endl;
}

## Input

12

## Output

10
Updated on 15-Mar-2022 06:34:12