0% found this document useful (0 votes)
30 views3 pages

Prime C++

The document contains C++ code to find the smallest prime number greater than or equal to a given number q using a vector of integers. It defines functions to find the smallest element in a vector, check if a number is prime, and calculate the greatest common divisor. The main function takes input n, defines a sample vector, finds the smallest element q, and calls the function to return the smallest prime number greater than or equal to q by iteratively calculating the least common multiple of the elements and q.

Uploaded by

Unknown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Prime C++

The document contains C++ code to find the smallest prime number greater than or equal to a given number q using a vector of integers. It defines functions to find the smallest element in a vector, check if a number is prime, and calculate the greatest common divisor. The main function takes input n, defines a sample vector, finds the smallest element q, and calls the function to return the smallest prime number greater than or equal to q by iteratively calculating the least common multiple of the elements and q.

Uploaded by

Unknown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <bits/stdc++.

h>

using namespace std;

int smallest(vector<int>arr){

int mini= arr[0];

for(int i=0;i<(int)arr.size();i++){

mini = min(mini,arr[i]);

return mini;

bool isPrime(int n) {

for (int i = 2; i * i <= n; i++) {

if (n % i == 0) {

return false;

return true;

int gcd(int a, int b) {

if (b == 0) {

return a;

} else {

return gcd(b, a % b);


}

int smallestPrimeNumber(int q, vector<int> arr) {

int ans = arr[0];

for(int i=1;i<(int)arr.size();i++){

if(arr[i]!=q){

ans=(((arr[i]*ans))/(gcd(arr[i],ans)));

cout<<q;

cout<<ans+q;

return ans+q;

int main() {

int n;

cin >> n;

vector<int> arr{3,4,5,1};

int q= smallest(arr);

int smallestPrime = smallestPrimeNumber(q, arr);

if (isPrime(smallestPrime)) {

cout << smallestPrime << endl;

} else {

cout << "None" << endl;

return 0;
}

You might also like