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 |
标程原来如此简单,只是复杂度高了许多!!但避免了精度问题!!#include <fstream> #include <vector> #include <iostream> using namespace std; typedef __int64 lint; //ifstream in("graveyard.in"); //ofstream out("graveyard.out"); vector<pair<lint, lint> > ans; void outLint(lint const & l) { char tmp[100]; sprintf(tmp, "%I64d", l); cout <<tmp; } int main() { char tmp[100]; lint N; cin >> tmp; sscanf(tmp, "%I64d", & N); lint l = 1; lint r = 1; lint sum = 1; for (;l*l <= N;) { if (sum < N) ++r, sum += r*r; else { if (sum == N) ans.push_back(make_pair(l, r)); sum -= l*l; ++l; } } cout <<ans.size()<<endl; for (int i = 0;i!=ans.size();++i) { outLint(ans[i].second-ans[i].first+1); cout <<' '; for (lint j = ans[i].first; j <=ans[i].second;++j) { outLint(j); cout<<' '; } cout <<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator