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;
}

【27.40%】【codeforces 599D】Spongebob and Squares的更多相关文章

  1. Codeforces 599D:Spongebob and Squares

    D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【51.27%】【codeforces 604A】Uncowed Forces

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【27.85%】【codeforces 743D】Chloe and pleasant prizes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【47.40%】【codeforces 743B】Chloe and the sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【40.17%】【codeforces 569B】Inventory

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【27.66%】【codeforces 592D】Super M

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【42.59%】【codeforces 602A】Two Bases

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. Java 学习(17): Java 泛型

    Java 泛型 Java 泛型(generics)是 JDK 5 中引入的一个新特性, 泛型提供了编译时类型安全检测机制,该机制允许程序员在编译时检测到非法的类型. 泛型的本质是参数化类型,也就是说将 ...

  2. 2 Java基础语法(keyword,标识符,凝视,常量,进制转换,变量,数据类型,数据类型转换)

    1:keyword(掌握) (1)被Java语言赋予特定含义的单词 (2)特点: 所有小写. (3)注意事项: A:goto和const作为保留字存在. B:类似于Notepad++这种高级记事本会对 ...

  3. ajax的get请求与编码

    window.onload = function(){ document.getElementById('username').onblur = function(){ var name = docu ...

  4. 8.Swift教程翻译系列——控制流之条件

    3.条件语句 常常会须要依据不同的情况来运行不同的代码. 你可能想要在错误发生的时候运行一段额外的代码,或者当某个值变得太高或者太低的时候给他输出出来.要实现这些需求,你能够使用条件分支. Swift ...

  5. Codeforces Round 363 Div. 1 (A,B,C,D,E,F)

    Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...

  6. python3怎样画二维点图

    引用自:http://www.cnblogs.com/super-zhang-828/p/4792206.html import matplotlib.pyplot as pltplt.plot([1 ...

  7. (转)bat批处理的注释语句

    在批处理中,段注释有一种比较常用的方法: goto start = 可以是多行文本,可以是命令 = 可以包含重定向符号和其他特殊字符 = 只要不包含 :start 这一行,就都是注释 :start 另 ...

  8. JS版微信6.0分享接口用法分析

    本文实例讲述了JS版微信6.0分享接口用法.分享给大家供大家参考,具体如下: 为了净化网络,整顿诱导分享及诱导关注行为,微信于2014年12月30日发布了<微信公众平台关于整顿诱导分享及诱导关注 ...

  9. [React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber

    Using a react-intl FormattedNumber component, we'll pass a Number and a few additional props in orde ...

  10. bootstrap课程4 bootstrap的css样式有哪些内容需要注意

    bootstrap课程4 bootstrap的css样式有哪些内容需要注意 一.总结 一句话总结: 1.如何选择产品(框架)的版本? 大版本下的最后一个版本,但是同时又要选择稳定的版本,也就是如果做产 ...