time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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 15 squares 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 is 15 + 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.

Examples

input

26

output

6

1 26

2 9

3 5

5 3

9 2

26 1

input

2

output

2

1 2

2 1

input

8

output

4

1 8

2 3

3 2

8 1

Note

In a 1 × 2 table there are 2 1 × 1 squares. So, 2 distinct squares in total.

In a 2 × 3 table there are 6 1 × 1 squares and 2 2 × 2 squares. That is equal to 8 squares in total.

【题目链接】:http://codeforces.com/problemset/problem/599/D

【题解】





其中(n+m)∑i = (n+m)(0+n-1)*n/2;

而∑i^2 = n*(n+1)*(2n+1)/6

所以x=n^2*m-(m+n)(0+n-1)*n/2+n(n+1)*(2n+1)/6

整理一下得

m= (6*x+n^3-n)/(3*n^2+n);

这样我们只要枚举一下n就可以快速得到相应的m了;

而因为随着n的增大m肯定是减少的(直觉告诉我);所以枚举结束的条件就是m< n;

然后把合法的m(能整除的)记录下来;

然后再逆序输出一遍就是n < m的情况了;

(如果出现n==m则要避免第二次再输出一次);

(n==m)的情况最多就出现一次的;

而那个x=n^2*m-(m+n)(0+n-1)*n/2+n(n+1)*(2n+1)/6

可以看到出现了n^2*m;不妨就看成n^3;

而x虽然可以很大开一个立方根里面变成10^6级的了;可以结束!



【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long using namespace std; const LL INF = 1e18;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0); LL ans[700000][2];
LL x,n; void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} int main()
{
rel(n);
LL flag =-1,num = 0;
for (LL i = 1;;i++)
{
LL fz = 6*n+i*i*i-i,temp = 3*(i*i+i),key = fz/temp;
if (fz % temp ==0 && i <=key)
{
num++;
if (i==key)
flag = num;
ans[num][0] = i;ans[num][1] = key;
}
if (key < i)
break;
}
if (flag == -1)
{
printf("%d\n",num*2);
for (int i = 1;i <= num;i++)
cout << ans[i][0] << " " << ans[i][1] << endl;
for (int i = num;i>=1;i--)
cout << ans[i][1] << " " << ans[i][0] << endl;
}
else
{
printf("%d\n",num*2-1);
for (int i = 1;i <= num;i++)
cout << ans[i][0] << " " << ans[i][1] << endl;
for (int i = num;i >=1;i--)
if (flag==i)
continue;
else
cout << ans[i][1] << " " << ans[i][0] << endl;
}
return 0;
}

最新文章

  1. thinkphp如何一次性的上传多个文件,在文件域中可以多选?
  2. WebService的开发、部署、调用
  3. 转:windows下命令行工具
  4. Unity3d 防止内存修改工具的小方法
  5. FileWriter和FileReader简单使用
  6. XAML概览 1(译自JeremyBytes.com)
  7. 关于 typings install 的使用
  8. Linux网络管理——网关作用
  9. MFC--自定义消息
  10. MyEclipse2014拷贝web工程
  11. SOD开源框架MSF(消息服务框架)进阶篇
  12. Max Sum of Max-K-sub-sequence hdu3415
  13. 5、C#基础 - C#的值类型
  14. PHP中变量的销毁
  15. rsyslog &amp; syslog详解
  16. 封装qq分享静态库到cocopod
  17. VBA读写ini 配置文件
  18. Jenkins持续集成 入门实践
  19. MapReduce核心 - - - Shuffle
  20. hdu 2844 coins(多重背包 二进制拆分法)

热门文章

  1. 洛谷——U10206 Cx的治疗
  2. 机房收费 &amp;amp; 廊院食堂
  3. Loadrunner11--输入license后提示违反许可证安全,禁止操作
  4. 【MemSQL Start[c]UP 3.0 - Round 1 B】 Lazy Security Guard
  5. CNTK 搞深度学习-1
  6. 自己定义View——坑、技巧、调优
  7. iOS数据存储简要笔记
  8. 3、Pycharm使用
  9. &lt;p&gt;&lt;img src=&quot;http://img.blog.csdn.net/20150823142545135?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
  10. 安装Win10+Ubuntu14.04双系统(uefi启动版)