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

小弟愚笨,不会打表。。。++!!用了750Ms,,,,,大牛看看可以改进不?

Posted by mayz at 2010-04-05 16:49:56 on Problem 2739 and last updated at 2010-04-05 16:57:14
#include<iostream>
#include<cmath>
#include<time.h>
using namespace std;
int main()
{
	int n,a,j,i,t,p;
	while(cin>>a)
	{
	     n=0;
		if(a==0) break;

		for(j=2;j<=sqrt((double)a);j++)
		 {
			 if(a%j==0) break;
		 }

	        if(j>sqrt((double)a))
		 {
			 n++;
		 }

		for(p=2;p<=a/2;p++)
		{
                  t=0;

		for(i=p;i<=a;i++)
		{
		   for(j=2;j<=sqrt((double)p);j++)
		    {
			 if(p%j==0) break;
		    }

		 if(j<=sqrt((double)p)) break;

                  for(j=2;j<=sqrt((double)i);j++)
		 {
			 if(i%j==0) break;
		 }

		 if(j>sqrt((double)i))
		 {
			 t+=i;

			 if(t>a) break;

			 if(t==a)
			 {
				 n++;
				 break;
			 }
		 }

		}
	}
	cout<<n<<endl;

	printf("%u secs.\n",clock()/CLOCKS_PER_SEC);
	}
	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