# Program to check if N is a Chiliagon Number

Given an integer N, the task is to check if N is a Chiliagon Number or not. If the number N is a Chiliagon Number then print “Yes” else print “No”.

Chiliagon Number
is class of figurate number. It has 1000 – sided polygon called Chiliagon. The N-th Chiliagon Number counts the 1000 number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few Chiliagon Numbers are 1, 1000, 2997, 5992, …

Examples:

Input: N = 1000
Output: Yes
Explanation:
Second chiliagon number is 1000

Input: 35
Output: No

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

1. The Kth term of the Chiliagon Number is given as 2. As we have to check that the given number can be expressed as a Chiliagon Number or not. This can be checked as follows:

=> => 3. If the value of K calculated using the above formula is an integer, then N is a Chiliagon Number.
4. Else N is not a Chiliagon Number.

Below is the implementation of the above approach:

## C++

 // C++ for the above approach  #include  using namespace std;     // Function to check that if N is  // Chiliagon Number or not  bool is_Chiliagon(int N)  {      float n          = (996 + sqrt(7984 * N + 992016))            / 1996;         // Condition to check if N is a      // Chiliagon Number      return (n - (int)n) == 0;  }     // Driver Code  int main()  {      // Given Number      int N = 1000;         // Function call      if (is_Chiliagon(N)) {          cout << "Yes";      }      else {          cout << "No";      }      return 0;  }

## Java

 // Java program for the above approach  class GFG{         // Function to check that if N is  // Chiliagon Number or not  static boolean is_Chiliagon(int N)   {      float n = (float)(996 + Math.sqrt(7984 * N +                                         992016)) / 1996;         // Condition to check if N is a      // Chiliagon Number      return (n - (int) n) == 0;  }     // Driver Code  public static void main(String s[])   {      // Given Number      int N = 1000;         // Function call      if (is_Chiliagon(N))       {          System.out.print("Yes");      }       else      {          System.out.print("No");      }  }  }     // This code is contributed by rutvik_56

## Python3

 # Python3 for the above approach  import math;     # Function to check that if N is  # Chiliagon Number or not  def is_Chiliagon(N):         n = (996 + math.sqrt(7984 * N +                           992016)) // 1996;         # Condition to check if N is a      # Chiliagon Number      return (n - int(n)) == 0;     # Driver Code     # Given Number  N = 1000;     # Function call  if (is_Chiliagon(N)):      print("Yes");  else:      print("No");     # This code is contributed by Code_Mech

## C#

 // C# program for the above approach  using System;  class GFG{         // Function to check that if N is  // Chiliagon Number or not  static bool is_Chiliagon(int N)   {      float n = (float)(996 + Math.Sqrt(7984 * N +                                         992016)) / 1996;         // Condition to check if N is a      // Chiliagon Number      return (n - (int) n) == 0;  }     // Driver Code  public static void Main()   {      // Given Number      int N = 1000;         // Function call      if (is_Chiliagon(N))       {          Console.Write("Yes");      }       else     {          Console.Write("No");      }  }  }     // This code is contributed by Code_Mech

Output:

Yes


Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : rutvik_56, Code_Mech

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.