View Code of Problem 27

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
    int a,b,flag=1,sum = 0,temp;
    while(cin>>a>>b){
        if(a>b){
            temp = a;
            a = b;
            b = temp;
        }
        sum=0;
        for(int i = a+1; i < b; i++){
            flag = 1;
            if( i == 1 )
                flag = 0;
            else{
            for(int j = 2; j <= sqrt(i); j++){
                if( i%j == 0){
                    flag = 0;
                break;
                }
            }
            }
            if( flag == 1 )
                sum+=i;
        }
        cout<<sum<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 27