很容易得到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()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
ull x, t, c, a, n, m; cin>>x;
int k = ;
//ns.push_back(1); ms.push_back(x);
int equ = ;
for(n = ; ; n++){
t = n*(n+)/;
c = (n)*(n+)*(*n+)/ - n*t;
if(c > x) break;
a = n*(n+) - t;
if((x - c) % a == ) {
m = (x-c)/a;
if(m < n) break;
ns.push_back(n);
ms.push_back(m);
k++;
if(m == n){
equ = ; break;
}
}
} if(equ){
k = *k-;
printf("%d\n", k);
int sz = ns.size();
for(int i = ; i < sz; i++){
printf("%I64d %I64d\n", ns[i], ms[i]);
}
for(int i = sz-; i >= ; i--){
printf("%I64d %I64d\n", ms[i], ns[i]);
}
}
else {
k = *k;
printf("%d\n", k);
int sz = ns.size();
for(int i = ; i < sz; i++){
printf("%I64d %I64d\n", ns[i], ms[i]);
}
for(int i = sz-; i >= ; i--){
printf("%I64d %I64d\n", ms[i], ns[i]);
}
} return ;
}

codeforces 599D Spongebob and Squares的更多相关文章

  1. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

  2. CF 599D Spongebob and Squares(数学)

    题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x ...

  3. [cf 599D] Spongebob and Squares

    据题意: $K=\sum\limits_{i=0}^{n-1}(n-i)*(m-i)$ $K=n^2m-(n+m)\sum{i}+\sum{i^2}$ 展开化简 $m=(6k-n+n^3)/(3n^2 ...

  4. Codeforces 599D:Spongebob and Squares

    D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举

    D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  6. codeforces #332 div 2 D. Spongebob and Squares

    http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...

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

    D. Spongebob and Squares   Spongebob is already tired trying to reason his weird actions and calcula ...

  8. 【27.40%】【codeforces 599D】Spongebob and Squares

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

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

    http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...

随机推荐

  1. 使用js页面添加或删除标签

    // 添加var container = document.getElementById('divAudio');container.appendChild(audio); // 删除var cont ...

  2. Github网站css加载不出来的处理方法(转,亲测有效)

    转载链接:https://blog.csdn.net/qq_36589706/article/details/80573008因为工作需求,自己会经常使用到github,但是突然有一天打开github ...

  3. POJ 2068 NIm (dp博弈,每个人都有特定的取最大值)

    题目大意: 有2n个人,从0开始编号,按编号奇偶分为两队,循环轮流取一堆有m个石子的石堆,偶数队先手,每个人至少取1个,至多取w[i]个,取走最后一个石子的队伍输.问偶数队是否能赢. 分析: 题目数据 ...

  4. DateAdapter

    import java.text.SimpleDateFormat;import java.util.Date; import javax.xml.bind.annotation.adapters.X ...

  5. 读取properties和xml中配置文件的值

    五种方式让你在java中读取properties文件内容不再是难题 在java中读取properties和xml文件中的方法:https://www.cnblogs.com/ConfidentLiu/ ...

  6. jvm 锁Lock

    自旋锁 线程想要获得一个对象的锁,如果没有得到,会继承占用CPU尝试获取锁, 线程不进入阻塞状态,仍然在Running 锁消除 public void lockTest() { String aa = ...

  7. HDU 5775 L - Bubble Sort 树状数组

    给定一段冒泡排序的代码,要求输出每个数字能到达的最右边的位置和最左边的位置的差 因为那段冒泡排序的代码是每次选取一个最小的数,放在左边的,所以,每个数最多能到达右边的位置应该是起始位置i+右边有多少个 ...

  8. java多线程,如何防止脏读数据

    多线程容易“非线程安全”的情况,是由于用了全局变量,而又没有很好的控制起情况.所以无论做什么程序,谨慎使用全局变量 "非线程安全"其实会在多个线程对同一个对象中的实例变量进行并发访 ...

  9. SVN的搭建(入门篇)

    如果转载,请注明出处,谢谢 1.安装SVN # yum install subversion 2.创建一个仓库 创建一个仓库svnrepos # svnadmin create /usr/svnrep ...

  10. Windows10 zip安装 MySQL8.0.12

    其实问题不大,就是win10永远有点奇葩的地方. 下载,解压,命名什么的我就不说了. 一 环境变量方便cmd使用mysql MYSQL_HOME = xxx // 就是安装的路径 Path = %MY ...