N prime numbers starting with K

Source: Internet
Author: User

N prime numbers starting with K
#include <iostream>
#include <cmath>
using namespace Std;
This function determines whether a number is a prime
int Sushu (int a)
... {
To determine whether a is four, if a is 4, the direct judgment is not a prime, this method is to solve the problem of this algorithm.
if (a==4)
return 1;
The judging process, starting from 2 to divide, until the number of the prescribed number
for (int i=2;i<sqrt (a); i++)
... {
The process of dividing and taking surplus
if (a%i==0)
... {
return 1;
}
}
return 0;
}
int main ()
... {
Defines two variables, num primes starting with First_num
int First_num,
Num
cout<< "Intput first_num" <<endl
<< "num" <<endl;
cin>>first_num>>num;
Define a variable count as the counter.
int count=0;
Whenever a prime number appears, the counter count plus one
for (first_num+=1;count<num;first_num++)
... {
int B=sushu (first_num);
if (b==0)
... {
cout<<first_num<<endl;
count++;
}
}
return 0;
}

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.