The topic description Xiao Ming and Xiao Hui Quarrel, Xiao Ming wants to see small Hui and beg to be forgiven. Xiao Hui gave Xiao Ming two number M and N (1<m<1000 and m<n<2000), between M to n Prime (the range contains M and N), the maximum number of adjacent two prime difference is small Hui decided not to see Xiao Ming's days, xiaoming very want to know a few days later to see small Hui, Clever you help xiaoming?
Input
Input m and N
Output
Maximum number of adjacent two prime difference
Sample input
10 30
Sample output
6
Tips
The prime number between 10 and 30 is 11 13 17 19 23 29, and the maximum of the adjacent two prime difference is 29-23 = 6
Answer
#include <iostream>using namespace Std;bool is (int n) { int m=0,i; for (I=1; i<n; i++) if (n%i==0) m++; if (m==1) return true; else return false;} int main () { int a,b,m[1000],i,n=0,max=0; cin>>a>>b; For (I=a, i<=b; i++) if (is (i)) { m[n++]=i; } for (i=0; i<n-1; i++) { if (M[i+1]-m[i]>max) max=m[i+1]-m[i]; } Cout<<max;;}
Some projects--Xiao Ming's punishment