Given a number **N**, the task is to find the index of smallest triangular number with **N digits**.

A number is termed as a triangular number if we can represent it in the form of a triangular grid of points such that the points form an equilateral triangle and each row contains as many points as the row number, i.e., the first row has one point, the second row has two points, the third row has three points and so on. The starting triangular numbers are 1, 3, 6, 10, 15, 21, 28…………

**Examples:**

Input:N = 2

Output:4

Smallest triangular number with 2 digits = 10, and 4 is the index of 10.

Input:N = 3

Output:14

Smallest triangular number with

3 digits = 105, and 14 is the index of 105.

**Approach:** The key observation in the problem is that the index of smallest triangular numbers with N digits form a series which is –

1, 4, 14, 45, 141...

The term of the index of smallest triangular number with N digits will be

Below is the implementation of the above approach:

## C++

`// C++ implementation of ` `// the above approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return index of smallest ` `// triangular no n digits ` `int` `findIndex(` `int` `n) ` `{ ` ` ` `float` `x = ` `sqrt` `(2 * ` `pow` `(10, (n - 1))); ` ` ` `return` `round(x); ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `n = 3; ` ` ` `cout << findIndex(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the above approach ` `class` `GFG{ ` ` ` `// Function to return index of smallest ` `// triangular no n digits ` `static` `double` `findIndex(` `int` `n) ` `{ ` ` ` `double` `x = Math.sqrt(` `2` `* Math.pow(` `10` `, (n - ` `1` `))); ` ` ` `return` `Math.round(x); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `3` `; ` ` ` `System.out.print(findIndex(n)); ` `} ` `} ` ` ` `// This code is contributed by shubham ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of ` `# the above approach ` `import` `math ` ` ` `# Function to return index of smallest ` `# triangular no n digits ` `def` `findIndex(n): ` ` ` ` ` `x ` `=` `math.sqrt(` `2` `*` `math.` `pow` `(` `10` `, (n ` `-` `1` `))); ` ` ` `return` `round` `(x); ` ` ` `# Driver Code ` `n ` `=` `3` `; ` `print` `(findIndex(n)); ` ` ` `# This code is contributed by Code_Mech ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the above approach ` `using` `System; ` `class` `GFG{ ` ` ` `// Function to return index of smallest ` `// triangular no n digits ` `static` `double` `findIndex(` `int` `n) ` `{ ` ` ` `double` `x = Math.Sqrt(2 * Math.Pow(10, (n - 1))); ` ` ` `return` `Math.Round(x); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `n = 3; ` ` ` `Console.Write(findIndex(n)); ` `} ` `} ` ` ` `// This code is contributed by AbhiThakur ` |

*chevron_right*

*filter_none*

**Output:**

14

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.

## Recommended Posts:

- Smallest triangular number larger than p
- Lexicographically smallest permutation with no digits at Original Index
- Find smallest number with given number of digits and sum of digits under given constraints
- Smallest number with given sum of digits and sum of square of digits
- Find smallest number with given number of digits and sum of digits
- Smallest odd number with N digits
- Smallest Even number with N digits
- Smallest even digits number not less than N
- Smallest odd digits number not less than N
- Find smallest number formed by inverting digits of given number N
- Find smallest possible Number from a given large Number with same count of digits
- Smallest number whose square has N digits
- Smallest number with sum of digits as N and divisible by 10^N
- Smallest number with at least n digits in factorial
- Find the smallest number whose sum of digits is N
- Smallest number whose sum of digits is square of N
- Find the kth smallest number with sum of digits as m
- Find the smallest number whose digits multiply to a given number n
- Smallest number k such that the product of digits of k is equal to n
- Smallest number greater than Y with sum of digits equal to X

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.