Open In App

Curzon Numbers

Last Updated : 05 Nov, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Given an integer N, check whether the given number is a Curzon Number or not.

A number N is said to be a Curzon Number if 2N + 1 is divisible by 2*N + 1.

Example: 

Input: N = 5 
Output: Yes 
Explanation: 
2^5 + 1 = 33 and 2*5 + 1 = 11 
Since 11 divides 33, so 5 is a curzon number.

Input: N = 10 
Output: No 
Explanation: 
2^10 + 1 = 1025 and 2*10 + 1 = 21 
1025 is not divisible by 21, so 10 is not a curzon number. 
 

Approach: The approach is to compute and check if 2N + 1 is divisible by 2*N + 1 or not.  

  • First find the value of 2*N + 1
  • Then find the value of 2N + 1
  • Check if the second value is divisible by the first value, then it is a Curzon Number, else not.

Below is the implementation of the above approach: 

C++




// C++ implementation of the approach
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to check if a number
// is a Curzon number or not
void checkIfCurzonNumber(int N)
{
 
    long int powerTerm, productTerm;
 
    // Find 2^N + 1
    powerTerm = pow(2, N) + 1;
 
    // Find 2*N + 1
    productTerm = 2 * N + 1;
 
    // Check for divisibility
    if (powerTerm % productTerm == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}
 
// Driver code
int main()
{
    long int N = 5;
    checkIfCurzonNumber(N);
 
    N = 10;
    checkIfCurzonNumber(N);
 
    return 0;
}


Java




// Java implementation of the approach
import java.io.*;
import java.util.*;
 
class GFG {
     
// Function to check if a number
// is a Curzon number or not
static void checkIfCurzonNumber(long N)
{
    double powerTerm, productTerm;
 
    // Find 2^N + 1
    powerTerm = Math.pow(2, N) + 1;
 
    // Find 2*N + 1
    productTerm = 2 * N + 1;
 
    // Check for divisibility
    if (powerTerm % productTerm == 0)
        System.out.println("Yes");
    else
        System.out.println("No");
}
 
// Driver code
public static void main(String[] args)
{
    long N = 5;
    checkIfCurzonNumber(N);
     
    N = 10;
    checkIfCurzonNumber(N);
}
}
 
// This code is contributed by coder001


Python3




# Python3 implementation of the approach
 
# Function to check if a number
# is a Curzon number or not
def checkIfCurzonNumber(N):
 
    powerTerm, productTerm = 0, 0
 
    # Find 2^N + 1
    powerTerm = pow(2, N) + 1
 
    # Find 2*N + 1
    productTerm = 2 * N + 1
 
    # Check for divisibility
    if (powerTerm % productTerm == 0):
        print("Yes")
    else:
        print("No")
 
# Driver code
if __name__ == '__main__':
     
    N = 5
    checkIfCurzonNumber(N)
 
    N = 10
    checkIfCurzonNumber(N)
 
# This code is contributed by mohit kumar 29


C#




// C# implementation of the approach
using System;
 
class GFG{
     
// Function to check if a number
// is a curzon number or not
static void checkIfCurzonNumber(long N)
{
    double powerTerm, productTerm;
 
    // Find 2^N + 1
    powerTerm = Math.Pow(2, N) + 1;
 
    // Find 2*N + 1
    productTerm = 2 * N + 1;
 
    // Check for divisibility
    if (powerTerm % productTerm == 0)
        Console.WriteLine("Yes");
    else
        Console.WriteLine("No");
}
 
// Driver code
static public void Main ()
{
    long N = 5;
    checkIfCurzonNumber(N);
     
    N = 10;
    checkIfCurzonNumber(N);
}
}
 
// This code is contributed by shubhamsingh10


Javascript




<script>
 
// Javascript implementation of the approach
 
// Function to check if a number
// is a Curzon number or not
function checkIfCurzonNumber(N)
{
    var powerTerm, productTerm;
     
    // Find 2^N + 1
    powerTerm = Math.pow(2, N) + 1;
     
    // Find 2*N + 1
    productTerm = 2 * N + 1;
     
    // Check for divisibility
    if (powerTerm % productTerm == 0)
    {
        document.write("Yes" + "</br>");
    }
    else
    {
        document.write("No");
    }
}
 
// Driver code
var N = 5;
checkIfCurzonNumber(N);
     
N = 10;
checkIfCurzonNumber(N);
 
// This code is contributed by Ankita saini
    
</script>


Output: 

Yes
No

 

Time complexity: O(log N)

Auxiliary Space: O(1)
 



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

Similar Reads