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 |
Re:暴力刚刚过,800多毫秒~~In Reply To:Re:暴力刚刚过,800多毫秒~~ Posted by:tanghaibao at 2008-12-28 22:49:26 纯暴力,204MS 240K #include<iostream> using namespace std; int Is_prime(int n) { int i,flag=0; for(i=2;i*i<=n;i++) { if(n%i==0) { flag=1; break; } } return flag; } int main() { int a,d,n; while(cin>>a>>d>>n&&a!=0) { int k=0; if(a==1) a+=d; while(1) { if(Is_prime(a)==0) { k++; if(k==n) { cout<<a<<endl; break; } } a+=d; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator