Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不会素数筛!!! 暴力也才 219 ms!

Posted by 810974380 at 2009-08-05 10:38:23 on Problem 3006
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator