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

Re:暴力刚刚过,800多毫秒~~

Posted by Acdone at 2009-03-30 22:44:04 on Problem 3006
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:
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