This problem requires the realization of a simple function to determine the prime number , And using this function to calculate the sum of prime numbers in a given interval .

A prime number can only be 1 A positive integer divisible by itself . be careful :1 It's not a prime ,2 It's a prime .
Function interface definition :
int prime( int p ); int PrimeSum( int m, int n );
Where function prime When the user passes in the parameter p Returns when it is a prime 1, Otherwise return 0; function PrimeSum Return interval [m, n] Sum of all primes in . The title guarantees the parameters passed in by the user m≤n.
Example of referee test procedure :
#include <stdio.h> #include <math.h> int prime( int p ); int PrimeSum( int m,
int n ); int main() { int m, n, p; scanf("%d %d", &m, &n); printf("Sum of ( ");
for( p=m; p<=n; p++ ) { if( prime(p) != 0 ) printf("%d ", p); } printf(") =
%d\n", PrimeSum(m, n)); return 0; } /* Your code will be embedded here */
sample input :
-1 10
sample output :
Sum of ( 2 3 5 7 ) = 17
In fact, there are many ways to judge prime numbers , The author inquired some algorithms , The most efficient method is selected , It is divided into the following steps :
1. Judge whether it is 2 or 3
2. Judge whether it is in 6 On both sides of the multiple of
3. Determine whether the number can be placed in the 6 The division of numbers on both sides of a multiple of

Submit after writing the program , The first result is wrong , It is found that there is a problem in determining the range of prime numbers , Because prime numbers must be positive , Excluding negative numbers
int prime(int p) { if(p<=0 || p==1){ return 0; }else if(p==2 || p==3){ return 1
; }else if(p%6 != 1 && p%6 != 5){ return 0; }else{ int tmp = (int)sqrt(p); int i
; for(i=5;i<=tmp;i+=6){ if(p%i==0 || p%(i+2)==0){ return 0; } } } return 1; }
int PrimeSum( int m, int n ){ int sum = 0; for(;m<=n;m++){ if(prime(m) != 0){
sum+= m; } } return sum; }

Technology