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

Source: Internet
Author: User
Tags 3x5 table

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 O f N and M, such that there is exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3x5 table there is 15squares with side one, 8 squares with side and 3 squares W ITH side Three. The total number of distinct squares in a 3x5 table is8 + 3 =.

Input

The first line of the input contains a single integer x (1≤ x ≤10)-the number of Squar Es 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
6
1 26
2 9
3 5
5 3
7 |
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 1x2 table there is 2 1x1 squares. So, 2 distinct squares in total.

In a 2x3 table there is 6 1x1 squares and 2 2x2 squares. That's equal to 8 squares in total.

Test Instructions : give you x, ask you how many kinds of n*m circumstances make, in the current rectangle within the number of small squares is X

Exercises

Column push: Sigma (K=1,k=min (n,m)) (n-k+1) * (m-k+1) =x;

We enumerate N and get M

///1085422276#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_backinline ll read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){        if(ch=='-') f=-1; ch=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar (); }returnx*F;}//****************************************Const intn=100000+ -;#defineMAXN 100000+5ll X;intMain () {x=read (); Vector<pair<ll, ll> >ans; ll Sum=0;  for(LL i=1; sum<=x; i++) {sum+=1ll*i*i; Long Longd=x-sum; Long Longk=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;}
Code

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.