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 |
不会素数筛!!! 暴力也才 219 ms!Accepted 144K 219MS C 437B #include<stdio.h> #include<math.h> int isprime(int n) { double w=sqrt(n*1.0)+1; int i; if(n==1) return 0; if(n==2) return 1; else { for(i=2;i<(int)w;i++) if(n%i==0) return 0; return 1; } } int main() {int a,d,n,x,num; while(scanf("%d %d %d",&a,&d,&n)){ if(a==0&&d==0&&n==0) break; x=a;num=0; while(1) { if(isprime(x)) num++; if(num==n) break; x+=d; } printf("%d\n",x); } return 0; Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator