Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
萌新贴码#include<stdio.h> #include<stdlib.h> #include<math.h> int a, d, n; int main() { int prime(int x); while(scanf("%d %d %d",&a,&d,&n)!=EOF) { if (a > 0 && a <= 9307 && d > 0 && d <= 346 && n > 0 && n <= 210) { int sum = 0, count = 0; for (int i = 0; ; i++) { sum = a + i*d; if (sum == 2 || sum == 3) count++; else if (sum == 1) continue; else if(prime(sum)) count++; if (count == n) break; } printf("%d\n", sum); } else exit(0); } if (prime(83)) printf("是素数"); else printf("不是素数"); return 0; } int prime(int x) { int i=2; for (; i <= sqrt(x); i++) { if (x%i == 0) return 0; } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator