Skip to content
Related Articles
Program to check if N is a Chiliagon Number
• Last Updated : 22 Apr, 2021

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

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 notbool 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 Codeint 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 approachclass GFG{      // Function to check that if N is// Chiliagon Number or notstatic 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 Codepublic 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 approachimport math;  # Function to check that if N is# Chiliagon Number or notdef 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 NumberN = 1000;  # Function callif (is_Chiliagon(N)):    print("Yes");else:    print("No");  # This code is contributed by Code_Mech

## C#

 // C# program for the above approachusing System;class GFG{      // Function to check that if N is// Chiliagon Number or notstatic 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 Codepublic 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

## Javascript

 
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.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with industry experts, please refer Geeks Classes Live

My Personal Notes arrow_drop_up