nyoj prime distance

prime distance problem

Time Limit: 3000 ms | Memory Limit: 65535 KB
Difficulty: 2
 
describe
Now you are given some numbers, and you are asked to write a program that prints the nearest primes to these integers, and prints the distance between them. If there are equidistant prime numbers on the left and right, output the value on the left and the corresponding distance.
If the input integer itself is a prime number, the prime number itself is output, and the distance output is 0
 
enter
The first line gives the number of test data sets N (0<N<=10000),
the next N lines each have an integer M (0<M<1000000),
output
Each line outputs two integers A B.
Where A represents the closest prime number to the corresponding test data, and B represents the distance between them.
sample input
3
6
8
10
Sample output
5 1
7 1
11 1

 

 

 

#include <iostream>
#include <cmath>
using namespace std;

bool is_Primer(int x)
{
if(x<2)
return false;
for(int i=2;i<=sqrt(x);++i)
if(x%i==0)
return false;

return true;
}






































break;
}

if(right-x<x-left)
cout<<right<<" "<<right-x<<endl;
else if(right-x>=x-left)
cout<<left<<" "<<x-left<<endl;
}
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324861297&siteId=291194637