Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
362 B
0
Indexable
Never
#include <iostream>

using namespace std;

bool prim(int n)
{
    int ok=1;
    for(int i = 2 ; i*i <= n&&ok==1;i++){
        if(n%i==0){
            ok = 0;
        }
    }
    return ok==1;
}
int i_prim(int n)
{
    int p1= n, p2=n;
    while(!prim(p1)){
        p1--;
    }
    while(!prim(p2)){
        p2++;
    }
    return p2-p1;
}