首页 > 其他 > 详细

CodeForces 599D Spongebob and Squares

时间:2016-05-07 20:52:07      阅读:213      评论:0      收藏:0      [点我收藏+]

先推导出公式x*(x+1)(3*y-x+1)=6*n,然后枚举求解。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long >ansx,ansy;
long long n;

int main()
{
    while(~scanf("%lld",&n)){
        ansx.clear();
        ansy.clear();
    for(long long x=1;;x++)
    {
        long long A=x*(x+1);
        long long B=6*n/A;
        long long y=(B+x-1)/3;
        if(y<x) break;
        if((6*n)%A!=0) continue;
        if((B+x-1)%3!=0) continue;
        ansx.push_back(x);
        ansy.push_back(y);

    }

    int u;
    if(ansx[ansx.size()-1]==ansy[ansx.size()-1])
        u=2*ansx.size()-1;
    else u=2*ansx.size();
    printf("%d\n",u);
    for(int i=0;i<ansx.size();i++)
    {
        printf("%lld %lld\n",ansx[i],ansy[i]);
    }
    for(int i=ansx.size()-1;i>=0;i--)
    {
        if(ansy[i]==ansx[i]) continue;
        printf("%lld %lld\n",ansy[i],ansx[i]);
    }
    }
    //x*(x+1)(3*y-x+1)=6*n
    return 0;
}

 

CodeForces 599D Spongebob and Squares

原文:http://www.cnblogs.com/zufezzt/p/5469129.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!