Http://codeforces.com/problemset/problem/599/D
To give you a number k let you ask for a n*m rectangle contains k square output how many such rectangles are
Can introduce a mathematical formula
We enumerate the squares of the i*i square inside the square containing the square that has (i*i) + (i-1) * (i-1) + (i-2) * (i-2) +...+ (1*1) is equal to b=i* (i-1) * (2*i-1)/6;
If K>b shows that the square inside this square is not enough, we need to add n (1*i) columns
If adding a column can increase the small square is (from 0 plus to i) i* (i+1)/2
So if (k-b)% (i* (i+1)/2) ==0 description happens to have (k-b)/(i* (i+1)/2) so many columns and then save it.
I can be directly violent with a maximum of 2000000.
#include <iostream>#include<cstring>#include<algorithm>#include<queue>#include<cstdio>#include<cstdlib>#include<cctype>#include<math.h>#include<ctype.h>using namespacestd;#defineMemset (A, B) memset (A,b,sizeof (a))#defineN 5001000typedefLong Longll;Const DoubleESP = 1e-8;#defineINF 0XFFFFFFFstructnode{ll x, y;} A[n];intMain () {ll k; while(SCANF ("%lld", &k)! =EOF) {ll sum=0; ll I; intflag=0; LL P=(ll) sqrt (k); for(i=1;; i++) { if(i>2000000|| I>p) Break; LL b= (i* (i+1)*(2*i+1)/6); ll c=i* (i+1)/2; if(k>=b&& (K-b)%c==0) {a[sum].x=i; A[sum++].y= (k-b)/c+i; } } if(a[sum-1].y==a[sum-2].x && a[sum-1].x==a[sum-2].y) {printf ("%lld\n", (sum-1)*2); for(i=0; i<sum;i++) printf ("%lld%lld\n", A[I].X,A[I].Y); for(i=sum-3; i>=0; i--) printf ("%lld%lld\n", a[i].y,a[i].x); } Else { if(a[sum-1].x==a[sum-1].y) {printf ("%d\n", sum*2-1); for(i=0; i<sum-1; i++) printf ("%lld%lld\n", A[I].X,A[I].Y); for(i=sum-1; i>=0; i--) printf ("%lld%lld\n", a[i].y,a[i].x); } Else{printf ("%lld\n", sum*2); for(i=0; i<sum;i++) printf ("%lld%lld\n", A[I].X,A[I].Y); for(i=sum-1; i>=0; i--) printf ("%lld%lld\n", a[i].y,a[i].x); } } } return 0;}
D. Spongebob and squares--cf599d (mathematics)