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