/*
* 二次筛素数
* POJ268————Prime Distance(数论,素数筛)
*/
#include<cstdio>
#include<vector>
using namespace std;
const int maxn = 1000005;
typedef long long LL;
bool is_prime_small[maxn];
bool is_prime[maxn];
vector <int> res;
int main() {
LL l,u;
while(scanf("%lld%lld",&l,&u) != EOF) {
for(LL i = 0;i*i < u;i++) {
is_prime_small[i] = true;
}
for(LL i = 0;i <= u-l;i++) {
is_prime[i] = true;
}
is_prime_small[1] = false;
if(l == 1)
is_prime[0] = false;
for(LL i = 2;i*i <= u;i++) {
if(is_prime_small[i]) {
for(LL j = 2*i;j*j <= u;j+=i) {
is_prime_small[j] = false;
}
for(LL j = max(2LL,(l+i-1)/i) * i;j <= u;j+=i) {
is_prime[j-l] = false;
}
}
}
res.clear();
for(LL i = l;i <= u;i++) {
if(is_prime[i - l]) {
res.push_back(i);
}
}
if(res.size() <= 1) {
printf("There are no adjacent primes.\n");
continue;
}
//避免这样写,可能会导致某些变量没有被赋值
// LL maxx = res[1] - res[0],b1,b2;
// LL minn = res[1] - res[0],a1,a2;
LL b1 = res[0],b2 = res[1],maxx = b2 - b1;
LL a1 = res[0],a2 = res[1],minn = a2 - a1;
for(LL i = 2;i < res.size();i++) {
if(maxx < res[i] - res[i-1]) {
maxx = res[i] - res[i - 1];
b2 = res[i];
b1 = res[i-1];
} else if(minn > res[i] - res[i-1]) {
minn = res[i] - res[i-1];
a2 = res[i];
a1 = res[i-1];
}
}
printf("%lld,%lld are closest, %lld,%lld are most distant.\n",a1,a2,b1,b2);
}
return 0;
}