Python Program to find the nth Kynea Number

Python Program to find the nth Kynea Number

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Given the number n, the task is to print nth Kynea Number in Python.

Kynea number is a mathematical integer of the type

nth = 4^n + 2^(n + 1) – 1, where n is a positive integer.

Which can be also written as

 

The initial Kynea numbers are

7, 23, 79, 287, 1087, 4223, 16639,…………..

Examples:

Example1:

Input:

Given nth number =6

Output:

The nth Kynea number = 4223

Example2:

Input:

Given nth number =8

Output:

The nth Kynea number = 66047

Python Program to find the nth Kynea Number

Below are the ways to program to find the nth Kynea Number.

Method #1: Using ** operator (Static Input)

Approach:

  • Give the number n as static input and store it in a variable.
  • Calculate the power of 2^n using the ** operator and store it in another variable say partialres.
  • Calculate the value of (partialres+1)^2-2 using ** and arithmetic operators.
  • Print the result.
  • The Exit of the Program.

Below is the implementation:

# Give the number n as static input and store it in a variable.
nthNum = 6
# Calculate the power of 2^n using the ** operator
# and store it in another variable say partialres.
partialres = 2**nthNum
# Calculate the value of (partialres+1)^2-2 
# using ** and arithmetic operators.
nthresult = (partialres+1)**2-2
# Print the result.
print('The nth Kynea number =', nthresult)

Output:

The nth Kynea number = 4223

Method #2: Using ** operator (User Input)

Approach:

  • Give the number n as user input using int(input()) and store it in a variable.
  • Calculate the power of 2^n using the ** operator and store it in another variable say partialres.
  • Calculate the value of (partialres+1)^2-2 using ** and arithmetic operators.
  • Print the result.
  • The Exit of the Program.

Below is the implementation:

# Give the number n as user input using int(input()) and store it in a variable.
nthNum = int(input('Enter some random nth Number = '))
# Calculate the power of 2^n using the ** operator
# and store it in another variable say partialres.
partialres = 2**nthNum
# Calculate the value of (partialres+1)^2-2 
# using ** and arithmetic operators.
nthresult = (partialres+1)**2-2
# Print the result.
print('The nth Kynea number =', nthresult)

Output:

Enter some random nth Number = 9
The nth Kynea number = 263167

Method #3: Using pow operator (Static Input)

Approach:

  • Give the number n as static input and store it in a variable.
  • Calculate the power of 2^n using the pow function and store it in another variable say partialres.
  • Calculate the value of (partialres+1)^2-2 using the pow function and arithmetic operators.
  • Print the result.
  • The Exit of the Program.

Below is the implementation:

# Give the number n as static input and store it in a variable.
nthNum = 6
# Calculate the power of 2^n using the pow function
# and store it in another variable say partialres.
partialres = 2**nthNum
# Calculate the value of (partialres+1)^2-2 
# using pow function and arithmetic operators.
nthresult = (partialres+1)**2-2
# Print the result.
print('The nth Kynea number =', nthresult)

Output:

The nth Kynea number = 4223

Method #4: Using pow operator (User Input)

Approach:

  • Give the number n as user input using int(input()) and store it in a variable.
  • Calculate the power of 2^n using the pow function and store it in another variable say partialres.
  • Calculate the value of (partialres+1)^2-2 using the pow function and arithmetic operators.
  • Print the result.
  • The Exit of the Program.

Below is the implementation:

# Give the number n as user input using int(input()) and store it in a variable.
nthNum = int(input('Enter some random nth Number = '))
# Calculate the power of 2^n using the pow function
# and store it in another variable say partialres.
partialres = 2**nthNum
# Calculate the value of (partialres+1)^2-2 
# using pow function and arithmetic operators.
nthresult = (partialres+1)**2-2
# Print the result.
print('The nth Kynea number =', nthresult)

Output:

Enter some random nth Number = 8
The nth Kynea number = 66047

Related Programs: