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

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 

Example

Let us see the following implementation to get better understanding −

#include 
using namespace std;
int solve(int n){
   if (n 

Input

12

Output

10
Updated on: 2022-03-15T06:34:12+05:30

224 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements