Bessie's Secret Pasture
Time limit1sMemory limit128 MB
Count the ordered quadruples (a,b,c,d) of non-negative integers whose squares sum to N, for N up to 10000.
- Level
Medium5 of 10
- Topics
- Hash map, Math, Brute force, Number theory
- Solved
- No attempts yet
Problem
Farmer John has cut an almost unlimited number of square pieces of sod (grass sections) of every integer side length from the pasture. (Sometimes FJ doesn't engage the blade properly and even makes squares of side length 0.) He has stacked them in neatly organized piles, which Bessie spotted one afternoon.
Bessie, always eager to put delicious grass in her secret pasture, decides to carry exactly four of these sod pieces to her pasture and cut them into sections so that they tile the () unit-square cells of the pasture with no gaps or overlaps.
Bessie wants to know how many different ways she can choose the four sod pieces. In other words, if the four squares have side lengths (each a non-negative integer), their total area must equal the pasture's area: .
For a pasture of size , Bessie could bring sod squares in these five different ways: , , , , . Order matters: for example, is a different choice from .
Input
- Line 1: A single integer .
Output
- Line 1: A single integer, the number of different ways Bessie can choose four sod pieces to tile her pasture.