程序代码:
#include<stdio.h> #include<stdlib.h> int prime(int m) { int i = 0; for (i = 2; i <= m / 2; i++) { if (m%i == 0) { return 0; } } return 1; } int main() { int m, n; int sum = 0; scanf("%d%d",&m,&n); for (; m <= n; m++) { if (prime(m)) { sum += m; } } printf("%d\n",sum); return 0; }