Problem P: 素数求和
#include<stdio.h> int main() { int n,i,a,j,s=0; scanf("%d",&n); n>=3&&n<=100; for(i=1;i<=n;i++) { scanf("%d",&a); for(j=2;j<=a/2;j++) { if(a%j==0) break; } if(j>a/2&&a!=1) { printf("%d ",a); s=s+a; }} printf("s=%d",s); return 0; }
#include<stdio.h> int main() { int n,i,a,j,s=0; scanf("%d",&n); n>=3&&n<=100; for(i=1;i<=n;i++) { scanf("%d",&a); for(j=2;j<=a/2;j++) { if(a%j==0) break; } if(j>a/2&&a!=1) { printf("%d ",a); s=s+a; }} printf("s=%d",s); return 0; }