Graveyard Design
Time Limit: 10000MS | Memory Limit: 64000K | |
Total Submissions: 6315 | Accepted: 1498 | |
Case Time Limit: 2000MS |
Description
King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard must consist of several sections, each of which must be a square of graves. All sections must have different number of graves.
After a consultation with his astrologer, King George decided that the lengths of section sides must be a sequence of successive positive integer numbers. A section with side length s contains s 2 graves. George has estimated the total number of graves that will be located on the graveyard and now wants to know all possible graveyard designs satisfying the condition. You were asked to find them.
After a consultation with his astrologer, King George decided that the lengths of section sides must be a sequence of successive positive integer numbers. A section with side length s contains s 2 graves. George has estimated the total number of graves that will be located on the graveyard and now wants to know all possible graveyard designs satisfying the condition. You were asked to find them.
Input
Input file contains n --- the number of graves to be located in the graveyard (1 <= n <= 10
14 ).
Output
On the first line of the output file print k --- the number of possible graveyard designs. Next k lines must contain the descriptions of the graveyards. Each line must start with l --- the number of sections in the corresponding graveyard, followed by l integers --- the lengths of section sides (successive positive integer numbers). Output line's in descending order of l.
Sample Input
2030
Sample Output
2 4 21 22 23 24 3 25 26 27
求连续的数平方和等于n的个数和他们分别是哪些数
/*头文件模板*/ #include <map> #include <set> #include <cmath> #include <ctime> #include <queue> #include <vector> #include <cctype> #include <cstdio> #include <string> #include <cstring> #include <sstream> #include <cstdlib> #include <typeinfo> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define pb push_back #define mp make_pair #define mem(a, x) memset(a, x, sizeof(a)) #define copy(a, b) memcpy(a, b, sizeof(a)) #define lson rt << 1, l, mid #define rson rt << 1|1, mid + 1, r #define FIN freopen("input.txt", "r", stdin) #define FOUT freopen("output.txt", "w", stdout) typedef long long LL; typedef pair<int, int > PII; typedef pair<int,string> PIS; typedef unsigned long long uLL; template<typename T> void print(T* p, T* q, string Gap = " ", bool flag = false) { int d = p < q ? 1 : -1; while(p != q) { if(flag) cout << Gap[0] << *p << Gap[1]; else cout << *p; p += d; if(p != q && !flag) cout << Gap; } cout << endl; } template<typename T> void print(const T &a, string bes = "") { int len = bes.length(); if(len >= 2)cout << bes[0] << a << bes[1] << endl; else cout << a << endl; } void IO_Init() { ios::sync_with_stdio(false); } LL LLabs(LL a) { return a > 0 ? a : -a; } const double PI = 3.1415926535898; const double eps = 1e-10; const int MAXM = 1e4 + 5; const int MAXN = 1e5 + 5; const LL INF = 0x3f3f3f3f; /*头文件模板*/ LL n; LL A[MAXN][2]; void solve(LL n) { //(l, r] int cnt = 0; LL l = 0, r = 1, sum = 0, res = 0; while(r <= sqrt(n)) { sum += r * r; while(sum > n && l < r) { l ++; sum -= l * l; } if(sum == n) { A[cnt][0] = l; A[cnt][1] = r; cnt ++; } r ++; } printf("%d\n", cnt); for(int i = 0;i < cnt;i ++){ printf("%lld", A[i][1] - A[i][0]); for(int j = A[i][0] + 1; j <= A[i][1];j ++){ printf(" %lld", j); } printf("\n"); } } int main() { while(~scanf("%lld", &n)) { solve(n); } return 0; }