POJ 2100 Graveyard Design

来源:互联网 发布:卫生网络答题 编辑:程序博客网 时间:2024/04/30 11:52
Graveyard Design
Time Limit: 10000MS Memory Limit: 64000KTotal Submissions: 7636 Accepted: 1900Case 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 s2 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 <= 1014 ).

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

24 21 22 23 243 25 26 27
题意: 给你一个数x  你的目的是找出有多少连续的数的和等于x  例子  2030 一共有2种情况,第一种是4个数的平方和 
分别是 21 22 23 24  第2 种情况是 3 个  数  分别是 25 26 27
思路  尺取选择区间。
代码 :
#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#define N 10005using namespace std;long long num[N],l[N],r[N];void solve(long long x){long long i,j;long long cnt=0;long long sum=0;long long left,right;left=right=1;long long sq;while(1){while(sum<x){sq=right*right;sum+=sq;right++;}if(sq>x) break;if(sum==x){num[++cnt]=right-left;r[cnt]=right;l[cnt]=left;}sum-=(left*left);left++;}printf("%lld\n",cnt);for(i=1;i<=cnt;i++){printf("%lld ",num[i]);for(j=l[i];j<r[i];j++){if(j==r[i]-1) printf("%lld\n",j);else printf("%lld ",j);}}return ;}int main(){long long x;while(~scanf("%lld",&x)){solve(x);}return 0;}


原创粉丝点击