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 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 test(s)

input

26

output

61 262 93 55 39 226 1

input

2

output

21 22 1

input

8

output

41 82 33 28 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.

题意:给你x,问你多少种n*m的情况使得,在当前这个矩形内小正方形的个数为x

题解:

列式推: sigma(k=1,k=min(n,m))(n-k+1)*(m-k+1)=x;

我们枚举n,得到m

///1085422276
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back

inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){
        if(ch==‘-‘)f=-1;ch=getchar();
    }
    while(ch>=‘0‘&&ch<=‘9‘){
        x=x*10+ch-‘0‘;ch=getchar();
    }return x*f;
}
//****************************************
const int N=100000+350;
#define maxn 100000+5

ll x;

int main()
{
    x=read();
    vector<pair<ll,  ll> >  ans;
    ll sum=0;
    for(ll i=1; sum<=x; i++)
    {
        sum+=1ll*i*i;
        long long d=x-sum;
        long long k=1LL*i*(i+1)/2;
        if(d%k==0)
        {
            ans.push_back({i, d/k+i});
            ans.push_back({d/k+i, i});
        }
    }
    sort(ans.begin(), ans.end());
    ans.resize(unique(ans.begin(), ans.end())-ans.begin());
    printf("%d\n", ans.size());
    for(ll i=0;i<ans.size();i++)
        printf("%I64d %I64d\n", ans[i].first, ans[i].second);
    return 0;
}

代码

时间: 2024-10-23 10:11:54

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

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?×

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 #404 (Div. 2) C 二分,水 D 数学,好题 E 分块

Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 题意:仓库容量n,每天运来m粮食,第 i 天被吃 i 粮食,问第几天仓库第一次空掉. tags:==SB题 注:二分边界判断,数据范围爆long long判断. // CF404 C #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000&

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 #428 (Div. 2) D. Winter is here 数学

链接: http://codeforces.com/contest/839/problem/D 题意: 给出一些数,求取出一些数,当他们的GCD大于0时,将数量乘GCD累加到答案上,求累加和. 题解: 这道题比赛的时候忘了考虑重复了,wa掉之后发现可能会出现重复,然而又不会写了.. 这道题需要知道一个公式就是 1*C(n,1)+2*C(n,2)+3*C(n,3)+...+n*C(n,n) = n*2^(n-1) 我们枚举GCD,统计为其倍数的数字数量,先假定其能组成的集合数为贡献, 但是我们发现