eolymp
bolt
Try our new interface for solving problems
Problems

Inverse Triangular Numbers

Inverse Triangular Numbers

A triangular number is the number of dots that can be packed in an equilateral triangle with n dots on a side. Here are a few example triangles, with their corresponding triangular numbers:

prb6008.gif

You can easily see that a triangular number is the additive equivalent of a factorial:

prb6008-02

Your team is to write a program that will, given an integer value, determine if it is a triangular number. If the given value is a triangular number, determine the number of dots on a side.

For example, if k is 10, your program will report that it is a triangular number with 4 dots on a side, since 10 = 4 + 3 + 2 + 1. If k is 11, your program will report that it is not a triangular number.

Input

Each line contains an integer n (0 < n < 109). The last line contains -1 and is not processed.

Output

Your program must determine if each integer n is a triangular number. If it is, print a line containing the number of dots on a side. If it is not a triangular number, print a line containing the string "bad".

Time limit 1 second
Memory limit 128 MiB
Input example #1
55
1
91
587
499500
-1
Output example #1
Case 1: 10
Case 2: 1
Case 3: 13
Case 4: bad
Case 5: 999
Source 2011 North Central America, November 12, Problem G