Time Limit: 10000MS | Memory Limit: 64000K | |
Total Submissions: 7357 | Accepted: 1816 | |
Case Time Limit: 2000MS |
Description
Input
Output
Sample Input
2030
Sample Output
2 4 21 22 23 24 3 25 26 27
Source
/* * @Author: Lyucheng * @Date: 2017-08-02 16:43:37 * @Last Modified by: Lyucheng * @Last Modified time: 2017-08-02 21:22:15 */ /* 题意:给你一个10^14的范围内的n,让你判断有多少连续子序列的平方和是n 思路:尺取 */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> #define LL long long #define INF 0xffffffff #define MAXN 10000001 using namespace std; LL n; LL l,r; LL _min; LL pos; struct Node{ int l,r; Node(){} Node(int _l,int _r):l(_l),r(_r){} }; vector<Node>v; void init(){ v.clear(); pos=0; } int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%I64d",&n); int cnt=((int)sqrt(n*1.0)) +1; init(); l=1,r=1; _min=INF; while(r*r<=n&&l*l<=n){ while(pos<n&&r*r<=n){ pos+=r*r; r++; } while(pos>n){ pos-=l*l; l++; } if(pos==n){ v.push_back(Node((int)l,(int)r-1)); pos-=l*l; l++; } } int tol=v.size(); printf("%d\n",tol); for(int i=0;i<tol;i++){ printf("%d ",v[i].r-v[i].l+1); for(int j=v[i].l;j<=v[i].r;j++){ printf(j==v[i].l?"%d":" %d",j); } printf("\n"); } return 0; }
原文:http://www.cnblogs.com/wuwangchuxin0924/p/7276921.html