[cf 599D] Spongebob and Squares

据题意:

  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;
}
时间: 2024-08-05 13:01:23

[cf 599D] Spongebob and Squares的相关文章

CodeForces 599D Spongebob and Squares

先推导出公式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("%

codeforce 599D Spongebob and Squares

很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e18就好. #include<bits/stdc++.h> using namespace std; typedef long long ull; vector<ull> ns; vector<ull> ms; //#define LOCAL int main() { #i

Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学

D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m colum

Codeforces Round #332 (Div. 2) D. Spongebob and Squares

Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3?×

[cf 599B] Spongebob and Joke

判断题,有点绕,注意在答案不唯一时的判断条件要依据B数组判断 #include <iostream> #include <algorithm> #include <map> using namespace std; int b[110000],f[110000]; map <int,int> Map,A; int main() { int n,i,m; cin >> n >> m; for(i=1;i<=n;++i) { cin

Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $ 化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$ 将n作为小的数,枚举n即可. 1 #include<iostream>

Codeforces Round #332 (Div. 2)

好菜,不说话了,说题. A - Patrick and Shopping 从一个点出发,要经过其他两个点,然后回到原地,求最小时间花费.只有四种情况,从中选一个最小的就行了. #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <math.h> #include <algorithm> using namespace

(CF#257)C. Jzzhu and Chocolate

Jzzhu has a big rectangular chocolate bar that consists of n?×?m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edg

微信 {&quot;errcode&quot;:40029,&quot;errmsg&quot;:&quot;invalid code, hints: [ req_id: Cf.y.a0389s108 ]&quot;}

{"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"} 问题:微信网页授权后,获取到 openid 了,一刷新又没了 微信网页授权获取到的 code 只能使用一次(5分钟内有效),使用一次后,马上失效. 页面授权跳转成功,根据 code 也换取到 openid 了. 此时刷新页面,并不会再次进行授权,而是直接刷新了一下上一次授权跳转后的链接,带的还是