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. 【转】MegaSAS RAID卡 BBU Learn Cycle周期的影响

    http://ju.outofmemory.cn/entry/140 背景 最近遇到有些带MegaSAS RAID卡的服务器,在业务高峰时突然IO负载飚升得很高,IO性能急剧下降,查了日志及各种设置最 ...

  2. Java Sleep() 与 Wait()的机制原理与区别

    一.概念.原理.区别    Java中的多线程是一种抢占式的机制而不是分时机制.线程主要有以下几种状态:可运行,运行,阻塞,死亡.抢占式机制指的是有多个线程处于可运行状态,但是只有一个线程在运行. 回 ...

  3. SQL删除数据库里所有表的外键,同时删除所有用户表

    SQL删除数据库里所有表的外键,同时删除所有用户表 删除所有的用户表的外键,直接将下面的代码拷贝到数据库里执行即可: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  4. HDU5697 刷题计划 dp+最小乘积生成树

    分析:就是不断递归寻找靠近边界的最优解 学习博客(必须先看这个): 1:http://www.cnblogs.com/autsky-jadek/p/3959446.html 2:http://blog ...

  5. web安全测试&渗透测试之sql注入~~

    渗透测试概念: 详见百度百科 http://baike.baidu.com/link?url=T3avJhH3_MunEIk9fPzEX5hcSv2IqQlhAfokBzAG4M1CztQrSbwsR ...

  6. <转>配置DNS辅助服务器:DNS系列之四

    配置DNS辅助服务器   在前面的博文中,我们介绍了如何在DNS服务器中创建常用的DNS记录,本文中我们要为大家介绍如何配置DNS的辅助服务器,同时也要介绍一下和辅助区域类似的存根区域. DNS辅助服 ...

  7. sql联接那点儿事儿

    1.交叉联接(cross join) select * from t.toy ,b.boy from toy as t cross join boy as b 其效果同select * from t. ...

  8. Windows7 32位下opencv与python2.66的环境配置

    刚接触Python和OpenCV,对两者都不太了解,因为今后学习会使用到这两种工具,特此学习配置.PS:本帖适用小白. 一. 需要的文件 1. OpenCV 可用OpenCV-2.3.1-win-su ...

  9. <Araxis Merge>保存文件

    1.保存文件 在任何时候都可以使用File菜单中的Save和Save As来保存文件.使用Save将修改的部分保存回文件.使用Save As将会用新名称来保存文件.在你右击文件面板的时候也可以从快捷菜 ...

  10. leetcode@ [310] Minimum Height Trees

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...