Open In App

James Joyce’s “Ulysses” sequence

Last Updated : 24 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

James Joyce’s “Ulysses” sequence represents the number of digits in NNN
First few terms in James Joyce’s “Ulysses” sequence are 
 

1, 2, 13, 155, 2185, 36306……..


Given an integer N, the task is to print the N-th term of James Joyce’s “Ulysses” sequence.
Examples: 
 

Input:
Output:
Explanation: 
Number of digits in 222 is 2 since 222 = 16
Input:
Output: 13 
 


 


Approach: The number of digits in Num is given by \lfloor (log_{10}(Num)) \rfloor + 1   . Therefore the number of digits in NNN is given by 
 

\lfloor (N^{N} * log_{10}(N)) \rfloor + 1


To see Joyce’s number in all its glory, we need to print about 370 million digits. Assuming 100 digits per line and 100 lines per page, this implies that something like 37 volumes, each of 1000 pages, would be required to write down N^{N^{N}}   explicitly. Joyce’s estimate in Ulysses was 33 volumes; not bad, considering his dismal performance in mathematics.
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 N-th term
// of James Joyce's "Ulysses" sequence.
int nthTerm(int n)
{
    return floor(pow(n, n) * log10(n)) + 1;
}
 
// Driver Code
int main()
{
    int n = 3;
    cout << nthTerm(n);
 
    return 0;
}

                    

Java

// Java implementation of
// the above approach
class GFG{
 
// Function to return N-th term
// of James Joyce's "Ulysses" sequence.
static int nthTerm(int n)
{
    return (int)(Math.floor(Math.pow(n, n) *
                            Math.log10(n)) + 1);
}
 
// Driver Code
public static void main(String[] args)
{
    int n = 3;
    System.out.print(nthTerm(n));
}
}
 
// This code is contributed by 29AjayKumar

                    

Python3

# Python3 implementation of the
# above approach
import math
 
# Function to return N-th term
# of James Joyce's "Ulysses" sequence.
def nthTerm(n):
     
    return (math.floor(math.pow(n, n) *
                       math.log10(n)) + 1);
 
# Driver Code
if __name__ == "__main__" :
     
    # Given number
    n = 3;
 
    # Function call
    print(nthTerm(n));
 
# This code is contributed by rock_cool

                    

C#

// C# implementation of
// the above approach
using System;
class GFG{
 
// Function to return N-th term
// of James Joyce's "Ulysses" sequence.
static int nthTerm(int n)
{
    return (int)(Math.Floor(Math.Pow(n, n) *
                            Math.Log10(n)) + 1);
}
 
// Driver Code
public static void Main()
{
    int n = 3;
    Console.Write(nthTerm(n));
}
}
 
// This code is contributed by Nidhi_biet

                    

Javascript

<script>
// Javascript implementation of
// the above approach
 
    // Function to return N-th term
    // of James Joyce's "Ulysses" sequence.
    function nthTerm( n)
    {
        return parseInt( (Math.floor(Math.pow(n, n) * Math.log10(n)) + 1));
    }
 
    // Driver Code
    let n = 3;
    document.write(nthTerm(n));
 
// This code is contributed by todaysgaurav
</script>

                    

Output: 
13

 

References: https://oeis.org/A054382
 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads