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

Source: Internet
Author: User

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 exactlyx distinct squares in the table consisting ofn rows and m Columns. For example, in a3?x?5 table there is squares with Side one,8 squares with side and 3 squares with side three. The total number of distinct squares in a 3?x?5 table is 15?+?8?+?3?=?26.

Input

The first line of the input contains a single integer x (1?≤? x≤?10)-the number of squares inside the tables Spongebob is interested in.

Output

First print a single integer k -the number of tables with exactlyx distinct squares inside.

Then print k pairs of integers describing the tables. Print the pairs in the order of increasingn, and in case of equality-in the order of increasingM.

Examplesinput
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?x?2 table There is 2 1?x?1 squares. So, 2 distinct squares in total.

In a 2?x?3 table There is 6 1?x?1 squares and 22?x?2 squares. That's equal to 8 squares in total.




Test Instructions: Given n, ask you how many pairs of a, b make a*b have n squares within the matrix.


Parse: Manually derive the formula for the number of squares in the a*b matrix and then brute force enumeration.



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




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

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.