codeforces 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()
{
#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的更多相关文章
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- CF 599D Spongebob and Squares(数学)
题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x ...
- [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 ...
- Codeforces 599D:Spongebob and Squares
D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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/ ...
- codeforces #332 div 2 D. Spongebob and Squares
http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...
- 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 ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...
随机推荐
- Codevs 2144 砝码称重 2
2144 砝码称重 2 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 有n个砝码,现在要称一个质量为m ...
- Jmeter3.2源码编译环境搭建(转)
1.下载jmeter3.2源码 https://github.com/apache/jmeter/tree/v3_2 https://blog.csdn.net/fly_to_higher/artic ...
- libaudit_plugin.so安装
#上传audit到mysql的plugin目录vim /etc/my.cnfplugin-load=AUDIT=libaudit_plugin.soaudit_json_file=1audit_jso ...
- BZOJ 2462 [BeiJing2011]矩阵模板 矩阵哈希
昨天卡了一天常数...然后发现吧$unsigned\space long\space long$改成$unsigned$就可以过了$qwq$ 先把每一行的前缀哈希求出,然后再竖着把每个前缀哈希值哈希起 ...
- 牛客假日团队赛1 A.蹄球锦标赛
链接: https://ac.nowcoder.com/acm/contest/918/A 题意: 为了准备即将到来的蹄球锦标赛,Farmer John正在训练他的N头奶牛(方便起见,编号为1-N,其 ...
- Python Unittest - 根据不同测试环境跳过用例详解
本文章会讲述以下几个内容: 1.Unittest 如何跳过用例 2.如何使用sys.argv 3.自动化测试项目中如何一套代码多套环境运行 一.Unittest跳过用例 @unittest.skip( ...
- Java中常用的数据源
几种常用的Java数据源解决方案 Java中的数据源就是javax.sql.DataSource.DataSource的创建可以有不同的实现. JNDI方式创建DataSource 以JNDI方式创建 ...
- Nologging操作对standby的影响
1.primary 首先要设置为 force_log mode ,然后再做备份,在应用到备库上. 2.switch over 之前需要检查v$database_block_corruption 视图 ...
- LeetCode 046 Permutations 全排列
Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have th ...
- win10卸载更新+关闭自动更新的方法
卸载更新方法: 左下角->设置->更新和安全->windows更新->高级选项->查看更新历史记录->卸载更新 关闭自动更新的方法:win+r 输入service ...