# Find Nth Kynea Number

Kynea numbers are near-squares of the form (2^n + 1)^2 - 2. This formula produce an integer value their initial sequence values is (7, 23, 79, 287, 1087, 4223, 16639, 66047, 263167, 1050623). Our goal is to write a program which is finding the nth kynea number which result is not exceed the size of integer.

Here given code implementation process.

``````/*
Java Program for
Find Nth Kynea Number
*/
public class KyneaNumber
{
public int findPower(int number, int size)
{
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
int result = number;
for (int i = 2; i <= size; ++i)
{
result = result * number;
}
return result;
}
}
public void nthKyneaNo(int number)
{
if (number <= 0)
{
// When invalid kynea number
return;
}
int result = (findPower(2, 2 * number) + findPower(2, number + 1) - 1);
System.out.println(number + " 'nth Kynea number is : " + result);
}
public static void main(String[] args)
{
// Test Case
}
}``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````// Include namespace system
using System;
/*
Csharp Program for
Find Nth Kynea Number
*/
public class KyneaNumber
{
public int findPower(int number, int size)
{
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
var result = number;
for (var i = 2; i <= size; ++i)
{
result = result * number;
}
return result;
}
}
public void nthKyneaNo(int number)
{
if (number <= 0)
{
// When invalid kynea number
return;
}
var result = (this.findPower(2, 2 * number) +
this.findPower(2, number + 1) - 1);
Console.WriteLine(number + " 'nth Kynea number is : " +
result);
}
public static void Main(String[] args)
{
// Test Case
}
}``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````// Include header file
#include <iostream>
using namespace std;
/*
C++ Program for
Find Nth Kynea Number
*/
class KyneaNumber
{
public: int findPower(int number, int size)
{
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
int result = number;
for (int i = 2; i <= size; ++i)
{
result = result *number;
}
return result;
}
}
void nthKyneaNo(int number)
{
if (number <= 0)
{
// When invalid kynea number
return;
}
int result = (this->findPower(2, 2 *number) +
this->findPower(2, number + 1) - 1);
cout << number << " \'nth Kynea number is : " << result << endl;
}
};
int main()
{
// Test Case
return 0;
}``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````// C Program for
// Find Nth Kynea Number
#include <stdio.h>

int pow_number(int number, int size)
{
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
int result = number;
for (int i = 2; i <= size; ++i)
{
result = result *number;
}
return result;
}
}
void kynea_number(int number)
{
if (number <= 0)
{
// When invalid kynea number
return;
}
printf("%d 'nth Kynea number is : %d\n", number,
(pow_number(2, 2 *number) + pow_number(2, number + 1) - 1));
}
int main()
{
kynea_number(4);
kynea_number(7);
kynea_number(9);
kynea_number(15);
return 0;
}``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````package main
import "fmt"
/*
Go Program for
Find Nth Kynea Number
*/

func findPower(number, size int) int {
if number == 0 {
return 0
} else if size == 0 {
return 1
} else {
var result int = number
for i := 2 ; i <= size ; i++ {
result = result * number
}
return result
}
}
func nthKyneaNo(number int) {
if number <= 0 {
// When invalid kynea number
return
}
var result int = (findPower(2, 2 * number) + findPower(2, number + 1) - 1)
fmt.Println(number, "'nth Kynea number is :", result)
}
func main() {

// Test Case
nthKyneaNo(4)
nthKyneaNo(7)
nthKyneaNo(9)
nthKyneaNo(15)
}``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````<?php
/*
Php Program for
Find Nth Kynea Number
*/
class KyneaNumber
{
public  function findPower(\$number, \$size)
{
if (\$number == 0)
{
return 0;
}
else if (\$size == 0)
{
return 1;
}
else
{
\$result = \$number;
for (\$i = 2; \$i <= \$size; ++\$i)
{
\$result = \$result * \$number;
}
return \$result;
}
}
public  function nthKyneaNo(\$number)
{
if (\$number <= 0)
{
// When invalid kynea number
return;
}
\$result = (\$this->findPower(2, 2 * \$number) +
\$this->findPower(2, \$number + 1) - 1);
printf("%s\n", \$number.
" 'nth Kynea number is : ".strval(\$result));
}
public static
function main(\$args)
{
// Test Case
}
}
KyneaNumber::main(array());``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````/*
Node JS Program for
Find Nth Kynea Number
*/
class KyneaNumber
{
findPower(number, size)
{
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
var result = number;
for (var i = 2; i <= size; ++i)
{
result = result * number;
}
return result;
}
}
nthKyneaNo(number)
{
if (number <= 0)
{
// When invalid kynea number
return;
}
var result = (this.findPower(2, 2 * number) +
this.findPower(2, number + 1) - 1);
console.log(number + " 'nth Kynea number is : " + result);
}
}

function main()
{
// Test Case
}
// Start program execution
main();``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````#  Python 3 Program for
#  Find Nth Kynea Number
class KyneaNumber :
def findPower(self, number, size) :
if (number == 0) :
return 0
elif (size == 0) :
return 1
else :
result = number
i = 2
while (i <= size) :
result = result * number
i += 1

return result

def nthKyneaNo(self, number) :
if (number <= 0) :
#  When invalid kynea number
return

result = (self.findPower(2, 2 * number) +
self.findPower(2, number + 1) - 1)
print(number ,"'nth Kynea number is :", result)

def main() :
#  Test Case

if __name__ == "__main__": main()``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````#  Ruby Program for
#  Find Nth Kynea Number
class KyneaNumber
def findPower(number, size)
if (number == 0)
return 0
elsif (size == 0)
return 1
else

result = number
i = 2
while (i <= size)
result = result * number
i += 1
end

return result
end

end

def nthKyneaNo(number)
if (number <= 0)
#  When invalid kynea number
return
end

result = (self.findPower(2, 2 * number) +
self.findPower(2, number + 1) - 1)
print(number ,"'nth Kynea number is : ", result, "\n")
end

end

def main()
#  Test Case
end

main()``````

#### Output

``````4'nth Kynea number is : 287
7'nth Kynea number is : 16639
9'nth Kynea number is : 263167
15'nth Kynea number is : 1073807359
``````
``````/*
Scala Program for
Find Nth Kynea Number
*/
class KyneaNumber()
{
def findPower(number: Int, size: Int): Int = {
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
var result: Int = number;
var i: Int = 2;
while (i <= size)
{
result = result * number;
i += 1;
}
return result;
}
}
def nthKyneaNo(number: Int): Unit = {
if (number <= 0)
{
// When invalid kynea number
return;
}
var result: Int = (findPower(2, 2 * number) +
findPower(2, number + 1) - 1);
println(""+ number + " 'nth Kynea number is : " + result);
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: KyneaNumber = new KyneaNumber();
// Test Case
}
}``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````import Foundation
/*
Swift 4 Program for
Find Nth Kynea Number
*/
class KyneaNumber
{
func findPower(_ number: Int, _ size: Int) -> Int
{
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
var result: Int = number;
var i: Int = 2;
while (i <= size)
{
result = result * number;
i += 1;
}
return result;
}
}
func nthKyneaNo(_ number: Int)
{
if (number <= 0)
{
// When invalid kynea number
return;
}
let result: Int = (self.findPower(2, 2 * number) +
self.findPower(2, number + 1) - 1);
print(String(number) + " \'nth Kynea number is : " + String(result));
}
static func main(_ args: [String])
{
// Test Case
}
}
KyneaNumber.main([String]());``````

#### Output

``````4 'nth Kynea number is : 287
7 'nth Kynea number is : 16639
9 'nth Kynea number is : 263167
15 'nth Kynea number is : 1073807359``````
``````/*
Kotlin Program for
Find Nth Kynea Number
*/
class KyneaNumber
{
fun findPower(number: Int, size: Int): Int
{
if (number == 0)
{
return 0;
}
else if (size == 0)
{
return 1;
}
else
{
var result: Int = number;
var i: Int = 2;
while (i <= size)
{
result = result * number;
i += 1;
}
return result;
}
}
fun nthKyneaNo(number: Int): Unit
{
if (number <= 0)
{
// When invalid kynea number
return;
}
val result: Int = (this.findPower(2, 2 * number) +
this.findPower(2, number + 1) - 1);
println(""+number + "'nth Kynea number is : " + result);
}
}
fun main(args: Array < String > ): Unit
{
// Test Case
}``````

#### Output

``````4'nth Kynea number is : 287
7'nth Kynea number is : 16639
9'nth Kynea number is : 263167
15'nth Kynea number is : 1073807359``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.