James Joyce’s “Ulysses” sequence
Last Updated :
24 Mar, 2021
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: 2
Output: 2
Explanation:
Number of digits in 222 is 2 since 222 = 16
Input: 3
Output: 13
Approach: The number of digits in Num is given by . Therefore the number of digits in NNN is given by
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 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++
#include <bits/stdc++.h>
using namespace std;
int nthTerm( int n)
{
return floor ( pow (n, n) * log10 (n)) + 1;
}
int main()
{
int n = 3;
cout << nthTerm(n);
return 0;
}
|
Java
class GFG{
static int nthTerm( int n)
{
return ( int )(Math.floor(Math.pow(n, n) *
Math.log10(n)) + 1 );
}
public static void main(String[] args)
{
int n = 3 ;
System.out.print(nthTerm(n));
}
}
|
Python3
import math
def nthTerm(n):
return (math.floor(math. pow (n, n) *
math.log10(n)) + 1 );
if __name__ = = "__main__" :
n = 3 ;
print (nthTerm(n));
|
C#
using System;
class GFG{
static int nthTerm( int n)
{
return ( int )(Math.Floor(Math.Pow(n, n) *
Math.Log10(n)) + 1);
}
public static void Main()
{
int n = 3;
Console.Write(nthTerm(n));
}
}
|
Javascript
<script>
function nthTerm( n)
{
return parseInt( (Math.floor(Math.pow(n, n) * Math.log10(n)) + 1));
}
let n = 3;
document.write(nthTerm(n));
</script>
|
References: https://oeis.org/A054382
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...