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:测试数据都通过了,我不明白为什么错了?

Posted by pb03005073 at 2006-12-18 20:16:47 on Problem 2739
In Reply To:测试数据都通过了,我不明白为什么错了? Posted by:pb03005073 at 2006-12-17 19:30:37
有哪位大侠指点一下小弟啊?
>

 源代码如下:
> #include <iostream>
> #include <vector>
> using namespace std;
> 
> vector<int> prime;
> 
> bool fprime(int n)
> {
> 	for(int i=2;i<n;i++)
> 	{
> 		if(n%i==0)return 0;
> 	}
> 	return 1;
> }
> int solver(int n)
> {
> 	int count=0;
> 	int begin=0;
> 	int x=0;
> 	int sum=0;
> 	
> 	while(prime.at(begin)<=n)
> 	{
> 		sum=0;
> 		x=begin;
> 		while(1)
> 		{
> 			sum+=prime.at(x);
> 			if(sum>n)
> 			{
> 				begin++;
> 				break;
> 			}
> 			else if(sum==n)
> 			{
> 				count++;
> 				begin++;
> 				break;
> 			}
> 			else 
> 				x++;
> 		}
> 	}
> 	return count;
> }
> 
> void main()
> {
> 	int n;	
> 	cin>>n;
> 	for(int i=2;i<10000;i++)
> 		if(fprime(i))prime.push_back(i);
> 
> 	while(n)
> 	{
> 		cout<<solver(n)<<endl;
> 		cin>>n;
> 	}
> 
> }

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