Iterated Logarithm or Log*(n) is the number of times the logarithm function must be iteratively applied before the result is less than or equal to 1.

**Applications:** It is used in analysis of algorithms (Refer Wiki for details)

## C++

`// Recursive CPP program to find value of` `// Iterated Logarithm` `#include <bits/stdc++.h>` `using` `namespace` `std;` `int` `_log(` `double` `x, ` `double` `base)` `{` ` ` `return` `(` `int` `)(` `log` `(x) / ` `log` `(base));` `}` `double` `recursiveLogStar(` `double` `n, ` `double` `b)` `{` ` ` `if` `(n > 1.0)` ` ` `return` `1.0 + recursiveLogStar(_log(n, b), b);` ` ` `else` ` ` `return` `0;` `}` `// Driver code` `int` `main()` `{` ` ` `int` `n = 100, base = 5;` ` ` `cout << ` `"Log*("` `<< n << ` `") = "` ` ` `<< recursiveLogStar(n, base) << ` `"\n"` `;` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Recursive Java program to ` `// find value of Iterated Logarithm` `import` `java.io.*;` `class` `GFG` `{` `static` `int` `_log(` `double` `x, ` ` ` `double` `base)` `{` ` ` `return` `(` `int` `)(Math.log(x) / ` ` ` `Math.log(base));` `}` `static` `double` `recursiveLogStar(` `double` `n, ` ` ` `double` `b)` `{` ` ` `if` `(n > ` `1.0` `)` ` ` `return` `1.0` `+ ` ` ` `recursiveLogStar(_log(n, ` ` ` `b), b);` ` ` `else` ` ` `return` `0` `;` `}` `// Driver code` `public` `static` `void` `main (String[] args) ` `{` ` ` `int` `n = ` `100` `, base = ` `5` `;` ` ` `System.out.println(` `"Log*("` `+ n + ` `") = "` `+` ` ` `recursiveLogStar(n, base));` `}` `}` `// This code is contributed by jit_t` |

*chevron_right*

*filter_none*

## Python3

`# Recursive Python3 program to find value of` `# Iterated Logarithm` `import` `math` `def` `_log(x, base):` ` ` `return` `(` `int` `)(math.log(x) ` `/` `math.log(base))` `def` `recursiveLogStar(n, b):` ` ` `if` `(n > ` `1.0` `):` ` ` `return` `1.0` `+` `recursiveLogStar(_log(n, b), b)` ` ` `else` `:` ` ` `return` `0` `# Driver code` `if` `__name__` `=` `=` `'__main__'` `:` ` ` `n ` `=` `100` ` ` `base ` `=` `5` ` ` `print` `(` `"Log*("` `, n, ` `") = "` `, recursiveLogStar(n, base))` `# This code is contributed by` `# Sanjit_Prasad` |

*chevron_right*

*filter_none*

## C#

`// Recursive C# program to ` `// find value of Iterated Logarithm` `using` `System;` `public` `class` `GFG{` `static` `int` `_log(` `double` `x, ` `double` `baset)` `{` ` ` `return` `(` `int` `)(Math.Log(x) / ` ` ` `Math.Log(baset));` `}` `static` `double` `recursiveLogStar(` `double` `n, ` ` ` `double` `b)` `{` ` ` `if` `(n > 1.0)` ` ` `return` `1.0 + ` ` ` `recursiveLogStar(_log(n, ` ` ` `b), b);` ` ` `else` ` ` `return` `0;` `}` `// Driver code` ` ` `static` `public` `void` `Main (){` ` ` ` ` `int` `n = 100, baset = 5;` ` ` `Console.WriteLine(` `"Log*("` `+ n + ` `") = "` `+` ` ` `recursiveLogStar(n, baset));` `}` `}` `// This code is contributed by ajit.` |

*chevron_right*

*filter_none*

## PHP

`<?php` `// Recursive PhP program to find ` `// value of Iterated Logarithm` `function` `_log(` `$x` `, ` `$base` `)` `{` ` ` `return` `(int)(log(` `$x` `) / log(` `$base` `));` `}` `function` `recursiveLogStar(` `$n` `, ` `$b` `)` `{` ` ` `if` `(` `$n` `> 1.0)` ` ` `return` `1.0 + ` ` ` `recursiveLogStar(_log(` `$n` `, ` ` ` `$b` `), ` `$b` `);` ` ` `else` ` ` `return` `0;` `}` `// Driver code` `$n` `= 100; ` `$base` `= 5;` `echo` `"Log*("` `, ` `$n` `, ` `")"` `,` `" = "` `,` `recursiveLogStar(` `$n` `, ` `$base` `), ` `"\n"` `;` `// This code is contributed by ajit` `?>` |

*chevron_right*

*filter_none*

**Output :**

Log*(100) = 2

**Iterative Implementation : **

## C++

`// Iterative CPP function to find value of` `// Iterated Logarithm` `int` `iterativeLogStar(` `double` `n, ` `double` `b)` `{` ` ` `int` `count = 0;` ` ` `while` `(n >= 1) {` ` ` `n = _log(n, b);` ` ` `count++;` ` ` `}` ` ` `return` `count;` `}` |

*chevron_right*

*filter_none*

## Java

`// Iterative Java function to find value of` `// Iterated Logarithm` `public` `static` `int` `iterativeLogStar(` `double` `n, ` `double` `b)` `{` ` ` `int` `count = ` `0` `;` ` ` `while` `(n >= ` `1` `) {` ` ` `n = _log(n, b);` ` ` `count++;` ` ` `}` ` ` `return` `count;` `}` `// This code is contributed by pratham76` |

*chevron_right*

*filter_none*

## Python3

`# Iterative Python function to find value of` `# Iterated Logarithm` `def` `iterativeLogStar(n, b):` ` ` `count ` `=` `0` ` ` `while` `(n >` `=` `1` `):` ` ` `n ` `=` `_log(n, b)` ` ` `count ` `=` `count ` `+` `1` ` ` `return` `count` `# This code is contributed by` `# Sanjit_Prasad` |

*chevron_right*

*filter_none*

## C#

`// Iterative C# function to find value of` `// Iterated Logarithm` `static` `int` `iterativeLogStar(` `double` `n, ` `double` `b)` `{` ` ` `int` `count = 0;` ` ` `while` `(n >= 1)` ` ` `{` ` ` `n = _log(n, b);` ` ` `count++;` ` ` `}` ` ` `return` `count;` `}` `// This code is contributed by rutvik_56` |

*chevron_right*

*filter_none*

This article is contributed by **Abhishek rajput**. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

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:

- Queries to find distance between two nodes of a Binary tree - O(logn) method
- Discrete logarithm (Find an integer k such that a^k is congruent modulo b)
- Logarithm
- Logarithm tricks for Competitive Programming
- Construct two N-length arrays with same-indexed elements as co-prime and a difference of N in their sum
- Queries to count minimum flips required to fill a binary submatrix with 0s only
- Count ways to split array into two equal sum subarrays by changing sign of any one array element
- Find a pair of intersecting ranges from a given array
- Bitwise AND of all unordered pairs from a given array
- Subsequences generated by including characters or ASCII value of characters of given string
- Calculate Bitwise OR of two integers from their given Bitwise AND and Bitwise XOR values
- Count numbers from given range having odd digits at odd places and even digits at even places
- Split array into equal length subsets with maximum sum of Kth largest element of each subset
- Split squares of first N natural numbers into two sets with minimum absolute difference of their sums