Prime and Onge teacher C Programming Cap 5th Chapter programming problem

Source: Internet
Author: User

Topic content:

We think 2 is the first prime number, 3 is the second Prime, 5 is the third prime, and so on.

Now, given the two integers n and m,0<n<=m<=200, your program calculates the number of primes between the nth prime number and the number of M primes, including the nth Prime and the first M prime.

Note: is the nth prime number to the number of M primes, not the prime number between N and M!

Input format:

Two positive integers, the first representing N, and the second representing M.

Output format:

An integer representing the nth prime number and the number of primes between the first m primes, including the nth Prime and the first M prime.

Input Sample:

2 4

Sample output:

15

time limit: 500ms memory limit: 32000kb
#include <stdio.h>intMain () {intn,m; scanf ("%d%d",&n,&m); intx=2;//Divisor    intCnt=0;//Count    intI//Dividend    intsum=0;//Add all numbers     Do{        intIsprime=1;  for(i=2; i<x;i++){            if(x%i==0) {IsPrime=0;//The prime number has been calculated.                  Break; }        }        if(isprime==1) {CNT++; if(cnt>=n&&cnt<=m) {//Pull out the prime number required by the topic. Sum+=x;//the number of primes required is added. }} x++; } while(0<cnt&&cnt<= $); printf ("%d\n", sum); return 0;}

Prime and Onge teacher C Programming Cap 5th Chapter programming problem

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.