33
Total Posts
3
Categories
24/7
Updated

C++

Test the truth of Bertrand conjecture (Bertrand conjecture is that there is at least one prime between n and 2n).

Published on Dec 22, 2025
#include <iostream>
using namespace std;

// Function to check if a number is prime
bool isPrime(int num) {
    if (num <= 1)
        return false;

    for (int i = 2; i * i <= num; i++) {
        if (num % i == 0)
            return false;
    }
    return true;
}

int main() {
    int n;
    bool found = false;

    cout << "Enter value of n (n > 1): ";
    cin >> n;

    cout << "Prime numbers between " << n << " and " << 2 * n << " are:\n";

    for (int i = n + 1; i <= 2 * n; i++) {
        if (isPrime(i)) {
            cout << i << " ";
            found = true;
        }
    }

    cout << endl;

    if (found)
        cout << "Bertrand conjecture is TRUE for n = " << n << endl;
    else
        cout << "Bertrand conjecture is FALSE for n = " << n << endl;

    return 0;
}

Documentation

Input

Enter value of n (n > 1): 10

Output
Prime numbers between 10 and 20 are:
11 13 17 19
Bertrand conjecture is TRUE for n = 10


For every integer n > 1, there exists at least one prime number between n and 2n.

Logic Used

  1. Read an integer n

  2. Check all numbers between n+1 and 2n

  3. Test each number for primality

  4. Display the prime(s) found and confirm the conjecture

 

Exam Notes

  • Prime checking is done using trial division up to √n

  • If at least one prime exists in (n, 2n), the conjecture holds

  • Bertrand’s conjecture has been proven true for all n > 1