首页 > 代码库 > Graveyard Design POJ - 2100

Graveyard Design POJ - 2100

   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.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
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<string>
 5 #include<cstring>
 6 #include<cmath>
 7 #define MAX 10000005
 8 using namespace std;
 9 typedef long long ll;
10 
11 ll n;
12 ll a[MAX],b[MAX],c[MAX];
13 
14 int main()
15 {  while(~scanf("%lld",&n)){
16        int temp=sqrt(n)+1;
17        ll l=1,r=1,t=0;    //用long long!!!调了一个多小时。。。 
18        ll ans=0;
19        while(r<=temp){
20               if(r*r>n) break;
21               ans+=r*r;           
22               while(ans>n){
23                    ans-=l*l;
24                    l++;
25               }
26               r++;
27               if(ans==n){
28                    t++;
29                    b[t]=r;
30                    c[t]=r-l;
31               }
32        }
33        if(t==0) printf("0\n");
34        else{
35            printf("%d\n",t);
36            for(int i=1;i<=t;i++){
37                  printf("%lld",c[i]);
38                  for(int j=c[i];j>0;j--) printf(" %lld",b[i]-j);
39                  printf("\n");
40              }
41        }    
42    } 
43 }

 

Graveyard Design POJ - 2100