Untitled
unknown
c_cpp
2 years ago
394 B
6
Indexable
#include <iostream>
#include <math.h>
using namespace std;
bool IsPrime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0) return false;
}
return true;
}
int primesumm(int a, int b) {
int summ = 0;
for (int i = a; i <= b; i++) {
if (IsPrime(i) == true) summ += i;
}
return summ;
}
int main() {
int a, b;
cin >> a >> b;
cout << primesumm(a, b);
}Editor is loading...
Leave a Comment