# Hilbert Number

Given a positive integer n, the task is to print nth Hilbert Number.

Hilbert Number: In mathematics, A Hilbert Number is a positive integer of the form 4*n + 1 , Where n is a non-negative integer.

The first few Hilbert numbers are –

1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97

Examples :

```Input : 5
Output: 21 ( i.e 4*5 + 1 )

Input : 9
Output: 37 (i.e 4*9 + 1 )

```

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

Approach:

• The n-th Hilbert Number of the sequence can be obtained by putting the value of n in the formula 4*n + 1.

Below is the implementation of the above idea:

## CPP

 `// CPP program to find ` `// nth hilbert Number ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Utility function to return ` `// Nth Hilbert Number ` `long` `nthHilbertNumber(``int` `n) ` `{ ` ` `  `    ``return` `4 * (n - 1) + 1; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` ` `  `    ``int` `n = 5; ` ` `  `    ``cout << nthHilbertNumber(n); ` ` `  `    ``return` `0; ` `} `

## JAVA

 `// JAVA program to find ` `// nth hilbert Number ` ` `  `class` `GFG { ` `    ``// Utility function to return ` `    ``// Nth Hilbert Number ` `    ``static` `long` `nthHilbertNumber(``int` `n) ` `    ``{ ` ` `  `        ``return` `4` `* (n - ``1``) + ``1``; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``int` `n = ``5``; ` ` `  `        ``System.out.println(nthHilbertNumber(n)); ` `    ``} ` `} `

## Python

 `# Python3 program to find ` `# nth hilbert Number  ` ` `  ` `  `# Utility function to return  ` `# Nth Hilbert Number ` `def` `nthHilbertNumber( n): ` `         `  `    ``return` `4``*``(n``-``1``) ``+` `1` `     `  `# Driver code ` ` `  `n ``=` `5` ` `  `print``(nthHilbertNumber(n)) `

## C#

 `// C# program to find ` `// nth hilbert Number ` ` `  `using` `System; ` `class` `GFG { ` `    ``// Utility function to return ` `    ``// Nth Hilbert Number ` `    ``static` `long` `nthHilbertNumber(``int` `n) ` `    ``{ ` ` `  `        ``return` `4 * (n - 1) + 1; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `Main() ` `    ``{ ` ` `  `        ``int` `n = 5; ` ` `  `        ``Console.WriteLine(nthHilbertNumber(n)); ` `    ``} ` `} `

## PHP

 ` `

Output:

```17
```

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.