Some projects--Xiao Ming's punishment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.