View Code of Problem 27

#include <iostream>
#include <math.h>
using namespace std;

bool isprime(int n){
  if(n==1)
    return false;
  double bound = sqrt(n);
  for(int j=2;j<bound+1;j++){
    if(n%j==0)
      return false;
  }
  return true;
}

int main(){
  int a,b,sum;
  while(scanf("%d%d",&a,&b)!=EOF){
    sum = 0;
    for(int j=a+1;j<b;j++){
      if(isprime(j))
        sum+=j;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 27