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 数学题枚举的更多相关文章

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

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

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #332 (Div. 二) B. Spongebob and Joke

    Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

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

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

  9. Codeforces Round #332 (Div. 2)

    水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...

随机推荐

  1. 一天一个Java基础——排序

    插入排序 直接插入排序: 当插入第i个数据元素k时,由前i-1个数据元素组成已排序的数据序列,将k与数据序列中各数据元素依次进行比较后,插入到数据序列的适当位置,使得插入后的数据序列仍是排序的. 直接 ...

  2. 【转】Android Studio系列教程一--下载与安装

    原文网址:http://stormzhang.com/devtools/2014/11/25/android-studio-tutorial1/ 背景 相信大家对Android Studio已经不陌生 ...

  3. Oracle RAC环境下如何更新patch(Rolling Patch)

    Oracle RAC数据库环境与单实例数据库环境有很多共性,也有很多异性.对于数据库补丁的更新同样如此,都可以通过opatch来完成.但RAC环境的补丁更新有几种不同的更新方式,甚至于可以在零停机的情 ...

  4. Zend Framework 入门(2)—多国语言支持

    如果你的项目想要支持多语言版本,那么就需要用到 Zend_Translate.Zend_Translate 的详细文档在这里,不过如果想偷懒的话,也很简单,在View Helpers 文档中介绍了如何 ...

  5. 不同语言的Unix时间戳

    如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)? Java time JavaScript Math.round(new Date().getTime()/1000)ge ...

  6. gitlab的使用

    Gitlab的使用 最近成功的在公司部署了gitlab,鉴于同学们还不会使用,这里写篇博客说明下.如果想安装gitlab的话,需要一些linux的基础知识,我在这里记录了我安装的参考<http: ...

  7. C/C++面试小知识点

    1.static有什么用途. 解答: 在函数体中,一个被声明为静态的变量在这一函数被调用过程中维持其值不变. 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所有函数访问,但不能被模块外其 ...

  8. Keep the Customer Satisfied

    题意: n个订单,每个订单有完成需要的天数,和限制的天数,求最多能完成多少订单 分析: 先按限制日期升序排列,若当前订单不能完成,和上面已选中的订单中需要天数中最大的比较,若比它小,则替换他. #in ...

  9. 试验Windows Embedded Standard 7 Service Pack 1 Evaluation Edition

    =========================================== 是否支持再使用 RT 7 Lite 精简 ? ================================= ...

  10. Myeclipse8.5 svn插件安装两种方式

    第一种方式:(亲测成功)第一步:准备插件包:site-1.6.18.zip解压该包里面有features和plugins文件夹,删除该包里面的xml结尾的文件. 第二:我的Myeclipse8.5安装 ...