[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+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=; scanf("%lld",&x);
for(i=;;++i)
{
long long n=i,m=(6LL*x-n+n*n*n)/(*n*n+*n);
if(n>m)break;
if((6LL*x-n+n*n*n)%(*n*n+*n)==)
{
S.push_back(make_pair(n,m));
}
}
if(S.back().first==S.back().second)
{
Ans=-;
}
Ans+=(int)S.size()<<; printf("%lld\n",Ans);
for(i=;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 ;
}
[cf 599D] Spongebob and Squares的更多相关文章
- CF 599D Spongebob and Squares(数学)
题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x ...
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- codeforces 599D Spongebob and Squares
很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...
- Codeforces 599D:Spongebob and Squares
D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- 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 ...
随机推荐
- PCB javascript解析钻孔(Excellon)格式实现方法
解析钻孔(Excellon)格式前首先得了解此格式,这样才能更好的解析呀. 一个钻孔里面包含的基本信息如下: 1.单位:公式mm,英制inch 2.省零方式:前省零,后省零 3.坐标方式:绝对坐标,相 ...
- 【Kafka】《Kafka权威指南》——从Kafka读取数据
应用程序使用 KafkaConsumer向 Kafka 订阅主题,并从订阅的主题上接收消息 . 从 Kafka 读取数据不同于从其他悄息系统读取数据,它涉及一些独特的概念和想法.如果不先理解 这些概念 ...
- Akka源码分析-Remote-网络链接生命周期
remote模式下,网络链接的生命周期往往影响着对应Actor的生命周期,那么网络链接的生命周期是怎么样的呢? 每一个与远程系统的链路都是四个状态之一:空闲.活跃.被守护.被隔离.远程系统的某个地址没 ...
- akka设计模式系列-While模式
While模式严格来说是while循环在Akka中的合理实现.while是开发过程中经常用到的语句之一,也是绝大部分编程语言都支持的语法.但while语句是一个循环,如果循环条件没有达到会一直执行wh ...
- SpringBoot SpringDataJPA 动态查询、多条件查询
Spring-data - JPA用的还是比较多的,之前在公司也一直在用,因为方便.下面我们来整理一下如何配置. pom.xml <?xml version="1.0" en ...
- BZOJ DZY Loves Math系列
⑤(BZOJ 3560) $\Sigma_{i_1|a_1}\Sigma_{i_2|a_2}\Sigma_{i_3|a_3}\Sigma_{i_4|a_4}...\Sigma_{i_n|a_n}\ph ...
- Parameter index out of range (1 > number of parameters, which is 0).
数据库错误:Parameter index out of range (1 > number of parameters, which is 0) ...
- C#图片辅助类,形成缩略图
完善一下别人的方法,成自己好用的工具 using System.Drawing; using System.Drawing.Imaging; namespace GXNUQzzx.Tools.Util ...
- MyBatis 配置控制台上显示sql语句(log4j.properties 之三)
### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.app ...
- 转 使用Hibernate操作数据库时报:No CurrentSessionContext configured! 异常
没有currentSession配置错误,即在我们使用currentSession的时候要在hibernate.cfg.xml中进行相关的事务配置:1.本地事务<property name=&q ...