3411 - 考试四 素数之和
Time Limit : 1 秒
Memory Limit : 128 MB
输入一个小于200的数,求出小于等于这个数的所有素数之和,当输入的数值大于200或小于0时输出“error”;
Input
输入一个整数
Output
输入的数不在范围之内返回error,反之返回素数和
Examples
Input Format
199
Output Format
4028
Solution C
#include <stdio.h> #include <math.h> int main() { int i,t,n,m=0; scanf("%d",&n); if(n>200 || n<0 ) printf("error"); else for(t=2;t<=n;t++) { for(i=2;i<n-1;i++) if(t%i==0)break; if(i>=t) m=m+t;} printf("%d",m); }