标签:
据题意:
k=Σ(i=0 to n-1)(n-i)*(m-i)
k=n2m -(n+m)Σ(i)+Σ(i2)
展开化简
m=(6k-n+n3)/(3n2+3n)
枚举n,验证整除,只做n<=m,其余反过来输出即可
#include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <vector> using namespace std; vector<pair<long long,long long> >S; int main() { long long x,i,Ans=0; scanf("%lld",&x); for(i=1;;++i) { long long n=i,m=(6LL*x-n+n*n*n)/(3*n*n+3*n); if(n>m)break; if((6LL*x-n+n*n*n)%(3*n*n+3*n)==0) { S.push_back(make_pair(n,m)); } } if(S.back().first==S.back().second) { Ans=-1; } Ans+=(int)S.size()<<1; printf("%lld\n",Ans); for(i=0;i<(int)S.size();++i) { printf("%lld %lld\n",S[i].first,S[i].second); } if(S.back().first==S.back().second) { S.pop_back(); } while(!S.empty()) { printf("%lld %lld\n",S.back().second,S.back().first); S.pop_back(); } return 0; }
[cf 599D] Spongebob and Squares
标签:
原文地址:http://www.cnblogs.com/Gster/p/4984330.html