#include<iostream>
using namespace std;
const unsigned maxn = 1300010;
int p[maxn], n;
bool np[maxn] = {true, true};
int main()
{
ios::sync_with_stdio(false);
for(int i=2; i<maxn; i++){
if(!np[i])
p[n++]=i;
for(int j=0;j<n&&i*p[j]<maxn;j++){
np[i*p[j]]=1;
if(!(i%p[j])) break;
}
}
while(cin>>n&&n){
if(!np[n]){
cout<<"0"<<endl;
continue;
}
int i=n,j=n;
while(np[i]) i--;
while(np[j]) j++;
cout<<j-i<<endl;
}
return 0;
}
素数怎么求的,明天再看看