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:
You can easily see that a triangular number is the additive equivalent of a factorial:
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 < 10^9
). 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".