The number of blocks that are easy to get NXM is
Then there is the question of summation, enumerating the n≤m of the two.
Then it turns into a*m + c = x. A,m≥0,x≥c. The worst is n^3≤x, as for the middle will not explode, the test of 1e18 is good.
#include <bits/stdc++.h>using namespaceStd;typedefLong LongUll;vector<ull>Ns;vector<ull>MS;//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endifull x, T, C, a, N, m; Cin>>x; intK =0; //Ns.push_back (1); Ms.push_back (x); intEqu =0; for(n =1; ; n++) {T= N (n+1)/2; C= (n) * (n+1)*(2*n+1)/6-NT; if(C > x) Break; A= N (n+1) -T; if((x-c)% A = =0) {m= (X-C)/A; if(M < n) Break; Ns.push_back (n); Ms.push_back (m); K++; if(M = =N) {equ=1; Break; } } } if(equ) {k=2*k-1; printf ("%d\n", K); intSZ =ns.size (); for(inti =0; I < sz; i++) {printf ("%i64d%i64d\n", Ns[i], ms[i]); } for(inti = sz-2; I >=0; i--) {printf ("%i64d%i64d\n", Ms[i], ns[i]); } } Else{k=2*K; printf ("%d\n", K); intSZ =ns.size (); for(inti =0; I < sz; i++) {printf ("%i64d%i64d\n", Ns[i], ms[i]); } for(inti = sz-1; I >=0; i--) {printf ("%i64d%i64d\n", Ms[i], ns[i]); } } return 0;}
Codeforce 599D Spongebob and squares