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:测试数据都通过了,我不明白为什么错了?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator