很容易得到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. moment.js的方法总结

    总结一个非常实用的日期工具类moment.js,日期获取,格式化等. 引入moment //import 方式 import moment from 'moment'; 设定moment区域为中国 / ...

  2. HTML5 为 <input> 增加的属性 ; 为 <form> 增加的如需属性

    HTML5 为 <input> 增加了如下属性: autocomplete autofocus form formaction formenctype formmethod formnov ...

  3. tput 命令行使用说明

    转载自:https://blog.csdn.net/fdipzone/article/details/9993961 什么是 tput?tput 命令将通过 terminfo 数据库对您的终端会话进行 ...

  4. DB2 触发器使用1

    本文基于多篇博文整理而来,目的是较全面的学会使用DB2触发器,后期再整理复杂的使用场景,看完本文应该能够自己创建一个基本的触发器. 1.什么是触发器当一个指定的 SQL 操作(如 DELETE,INS ...

  5. 成功安装tesserocr

    首先按照官网的操作,出现了下面的错误. 错误描述: x86_64-linux-gnu-gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录 er ...

  6. 记录一个直接操作mediawiki数据库遇到的坑

    我的mediawiki使用的是postgresql数据库,当你进入到mediawiki数据库时,运行sql select * from pg_tables; 你会发现mediawiki的数据表的sch ...

  7. SpringBoot源码篇:深度分析SpringBoot如何省去web.xml

    一.前言 从本博文开始,正式开启Spring及SpringBoot源码分析之旅.这可能是一个漫长的过程,因为本人之前阅读源码都是很片面的,对Spring源码没有一个系统的认识.从本文开始我会持续更新, ...

  8. 织梦通过 phpmyadmin 导出的数据,再次导入的时候报错

    错误提示: #1291 – Column 'nature' has duplicated value '婆婆妈妈' in SET SQL 查询: -- -- 导出表中的数据 `dede_member_ ...

  9. pat1084. Broken Keyboard (20)

    1084. Broken Keyboard (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue On a ...

  10. SQLServer常见性能问题

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...