Time Limit: 10000MS | Memory Limit: 64000K | |
Total Submissions: 6370 | Accepted: 1514 | |
Case Time Limit: 2000MS |
Description
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
Output
Sample Input
2030
Sample Output
2 4 21 22 23 243 25 26 27
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <climits> #include <cmath> using namespace std; const int N = 1000010; struct node { long long left, right, num; }p[N]; int main() { long long n; while(scanf("%lld", &n)!=EOF) { int cnt=0; long long l=1, r=1, sum=0; while(r*r<=n||l*l<=n) { if(sum<n) { sum+=(r*r); r++; } else if(sum==n) { p[cnt].num=r-l,p[cnt].left=l,p[cnt].right=r-1; sum+=r*r; cnt++; r++; } else { sum-=(l*l); l++; } } printf("%d\n",cnt); for(int i=0;i<cnt;i++) { printf("%I64d ",p[i].num); for(long long j=p[i].left;j<=p[i].right;j++) { printf("%I64d%c",j,j==p[i].right?'\n':' '); } } } return 0; }