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

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.

题意:给定n,问你有存在多少对a,b使得a*b的矩阵内有n个正方形。

分析:手动推导一下a*b的矩阵中正方形个数的公式然后暴力枚举即可。

#include <cstdio>
#include <iostream>
using namespace std;
struct thing
{
	long long x,y;
} ans[1000000];
long long a,n,tot,same;
int main()
{
	cin.sync_with_stdio(false);
	cin>>n;
	long long i = 1;
	while(true)
	{
		long long b = (i-1)*i*(2*i-1)/6 - i*i*(i-1)/2;
		if(b >= n) break;
		long long k = i*(i+1)/2;
		if((n - b) / k < i) break;
		if((n - b) % k == 0)
		{
			ans[++tot].x = i;
			ans[tot].y = (n - b) / k;
			if(ans[tot].x == ans[tot].y) same++;
		}
		i++;
	}
	cout<<2*tot-same<<endl;
	for(int i = 1;i <= tot;i++) cout<<ans[i].x<<" "<<ans[i].y<<endl;
	for(int i = tot;i;i--)
	 if(ans[i].x != ans[i].y)
	  cout<<ans[i].y<<" "<<ans[i].x<<endl;
 } 
时间: 2024-11-05 02:17:52

Codeforces Round #332 (Div. 2) D. Spongebob and Squares的相关文章

Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学

D. Spongebob and Squares 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 colum

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

http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $ 化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$ 将n作为小的数,枚举n即可. 1 #include<iostream>

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

Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not

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 on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1

Codeforces Round #332 (Div. 2)

好菜,不说话了,说题. A - Patrick and Shopping 从一个点出发,要经过其他两个点,然后回到原地,求最小时间花费.只有四种情况,从中选一个最小的就行了. #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <math.h> #include <algorithm> using namespace

Codeforces Round #332 (Div. 2)A. Patrick and Shopping 水

A. Patrick and Shopping Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop an

2017-5-18-Train: Codeforces Round #332 (Div. 2)

A. Patrick and Shopping(模拟题) Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first sh

Codeforces Round #337 (Div. 2) B. Vika and Squares 水题

B. Vika and Squares Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of s

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/