Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 < 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
Advertisements
