Subject background
Background is description, description is background.
The title describes
Farmmer John recently harvested almost unlimited pieces of grass and piled them on the clearing. These pastures are all square and have side lengths of non-negative integer length (of course there is 0). One day its cow Bessie discovered these delicious pastures, so she hoped to plant them on her secret pasture. He always divides the turf into 1*1 small pieces to put into N grids on his ranch.
What Bessie is interested in is how many different ways she can choose four. If N=4, then she has 5 different distributions: (1,1,1,1),(2,0,0,0),(0,2,0,0),(0,0,2 ,0),(0,0,0,2), the number in the parentheses indicates the side length. Note that the order is not important here, such as (1,2,3,4) and (4,3,2,1) are two different methods.
The input format
is only one line, an integer N.
The output format is
also one line, containing an integer, which is the total number of solutions.
Input and output example
Input #1
4
Output #1
5
Description/Hint
For 100% data, 1<=N<=10000.
Code:
#include<iostream>
using namespace std;
int main()
{
int n, a = 0, b = 0, c = 0, d = 0, count = 0;
cin >> n;
for(a = 0; a * a <= n; a++)
for(b = 0; a * a + b * b <= n; b++)
for(c = 0; a * a + b * b + c * c <= n; c++)
for(d = 0; a * a + b * b + c * c + d * d <= n; d++)
if(a * a + b * b + c * c + d * d == n) count++;
cout << count << endl;
return 0;
}