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/599/problem/D
Description
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 × 5 table there are 15squares with side one, 8 squares with side two and 3 squares with side three. The total number of distinct squares in a 3 × 5 table is15 + 8 + 3 = 26.
Input
The first line of the input contains a single integer x (1 ≤ x ≤ 1018) — the number of squares inside the tables Spongebob is interested in.
Output
First print a single integer k — the number of tables with exactly x distinct squares inside.
Then print k pairs of integers describing the tables. Print the pairs in the order of increasing n, and in case of equality — in the order of increasing m.
Sample Input
26
Sample Output
6
1 26
2 9
3 5
5 3
9 2
26 1
HINT
题意
给你x,然后让你找有多少个n*m的矩形,可以由x个相同的多边形组成
题解:
数学题,这道题实际上是问,f(n,m) = sigma(k=1,k=min(n,m))(n-k+1)*(m-k+1)=x的解有多少个
化简之后,我们可以得到f(n,m) = n^2m+n^2+n*m+n-(n+1)*n/2*(n+m+2)+n*(n+1)*(2n+1)/6
这个式子是一个关于m的一次函数,我们枚举n就好了
就可以求m了,注意break条件
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std; struct node
{
long long x,y;
};
bool cmp(node a,node b)
{
return a.y>b.y;
}
vector<node> ans1;
int main()
{
long long x;cin>>x;
for(long long i = ;i<=10000000LL||i*i*i<=x;i++)
{
long long a = (i*i+i-(i+)*i/2LL);
long long b = (i*i+i-(i+)*i*i/2LL-(i+)*i+(i*(i+)*(*i+)/));
long long y = x;
long long t= (y-b)/a;
if(i>t)continue;
if(a*t+b==y)
{
if(i==t)
{
node k;k.x = i,k.y = t;
ans1.push_back(k);
}
else
{
node k;k.x = i,k.y = t;
ans1.push_back(k);
k.x = t,k.y = i;
ans1.push_back(k);
}
}
}
sort(ans1.begin(),ans1.end(),cmp);
printf("%d\n",ans1.size());
for(int i=;i<ans1.size();i++)
{
printf("%lld %lld\n",ans1[i].x,ans1[i].y);
}
}
代码
Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举的更多相关文章
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...
- 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 ...
- Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题
B. Spongebob and Joke Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599 ...
- Codeforces Round #332 (Div. 二) B. Spongebob and Joke
Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...
- Codeforces Round #332 (Div. 2)_B. Spongebob and Joke
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #332 (Div. 2)B. Spongebob and Joke
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟
B. Spongebob and Joke While Patrick was gone shopping, Spongebob decided to play a little trick ...
- 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)
水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...
随机推荐
- Mac终端编译运行C++
1.在编辑器中写好C++代码 2.打开终端打开文件对应的地址 3.用g++命令来编译.cpp文件 4.用./文件名来运行 观察文件的目录可发现 g++ 源文件名 编译源文件,产生a.out ./文件名 ...
- 【Unity3D】枪战游戏—弹孔设置
以子弹为原点,发射射线,如果射线检测到障碍物,则返回射线与障碍物的碰撞点 在该点处实例化出弹孔贴图 void Update () { transform.Translate (Vector3.forw ...
- iE6、7、8、9、10、11兼容的Cookie
<%@ Master Language="C#" Debug="true" AutoEventWireup="true" Inheri ...
- java web 学习三(Tomcat 服务器学习和使用2)
一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命令的用法如下:
- ThinkAndroid是简洁,快速的进行Android应用程序的框架
ThinkAndroid简介ThinkAndroid是一个免费的开源的.简易的.遵循Apache2开源协议发布的Android开发框架,其开发宗旨是简单.快速的进行Android应用程序的开发,包含A ...
- 如何解决Rally模板提示angular js加载错误
[前言] Rally是一个开源测试工具,用于测试openstack各个组件的性能 在使用Rally测试完毕后,一般会生成测试报告,这点很重要.但是原生态的Rally报告模板angular js框架是从 ...
- 单片机usb转串口的时灵时不灵的解答
写这篇博客,首先检讨一下自己,因为以前串口的程序,也和步进电机一样,时灵时不灵,我现在终于知道这是为什么了,因为51上有三个串口,一个公口,一个母口,一个usb转串口,这样的话,串口有3个了,我手头上 ...
- netty的入门
netty是什么? netty是一个基于NIO的通信框架,对于传统计算机,系统的瓶颈一直在输入输出设备上,计算速度超过IO速度,所以对于i o的性能提高异常重要. 什么是NIO? 非阻塞IO,N表示n ...
- 当rsync遇到非默认端口的ssh
在使用rsync使用ssh协议,来同步远程文件的方法,rsync -zvrtopg -e ssh但是如果遇到ssh不是22端口的时候使用rsync -zvrtopg -e ‘ssh -p 端口’特别是 ...
- 机器学习中的数学(4)-线性判别分析(LDA), 主成分分析(PCA)
版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...