- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 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

- Related Questions & Answers
- Finding next prime number to a given number using JavaScript
- Different Methods to find Prime Number in Python
- Different Methods to find Prime Number in Java
- Java Program to display a prime number less than the given number
- Program to find all prime factors of a given number in sorted order in Python
- Program to find Prime Numbers Between given Interval in C++
- Different Methods to find Prime Number in Python Program
- Python Program to Find if a Number is Prime or Not Prime Using Recursion
- Find Largest Special Prime which is less than or equal to a given number in C++
- Nearest prime less than given number n C++
- C++ code to find array from given array with conditions
- C++ code to find out number of battery combos
- Python - Find the number of prime numbers within a given range of numbers
- Find the Number of Prefix Sum Prime in Given Range Query using C++
- Analysis of Different Methods to find Prime Number in Python

Advertisements