#include // Problem 11480 // Let G,B,R be the number of balls of each colour. // The range of values for B is between 2 and floor(N/2)-1 // Imagine B is fixed. Then R must satisfy 2 constraints: // (1) R <= B-1 // (2) R+B+(B+1) <= R+B+G = N, which means R <= N-2B-1 // Thus, R can take any value between 1 and min(B-1,N-2B-1) // Once B and R are chosen, G is uniquely determined. // So, we just have to add up min(B-1,N-2B-1) for B=2..floor(N/2)-1 // Now, B-1 <= N-2B-1 iff B <= N/3 // So we can split up the sum into two pieces: // The sum of (B-1) for B=2..floor(N/3), which is (floor(N/3)-1)floor(N/3)/2 // and the sum of (N-2B-1) for B=floor(N/3)+1 to floor(N/2)-1, which is // (N-1)(floor(N/2)-1-floor(N/3))-(floor(N/2)-1)floor(N/2) // +floor(N/3)(floor(N/3)+1) int main() { long long N; int counter = 1; cin >> N; while (N) { long long N3 = N/3; long long N2 = N/2; long long r = (N3-1)*N3/2+(N-1)*(N2-1-N3)-(N2-1)*N2+N3*(N3+1); cout << "Case " << counter << ": " << r << "\n"; counter++; cin >> N; } }