Curzon Numbers - GeeksforGeeks

05 Nov, 2021
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++
Java
Python3
C#
Javascript
// C++ implementation of the approach #include <bits/stdc++.h>using namespace std; // Function to check if a number// is a Curzon number or notvoid 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 codeint main(){    long int N = 5;    checkIfCurzonNumber(N);     N = 10;    checkIfCurzonNumber(N);     return 0;}
// Java implementation of the approachimport java.io.*;import java.util.*; class GFG {     // Function to check if a number// is a Curzon number or notstatic 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 codepublic static void main(String[] args){    long N = 5;    checkIfCurzonNumber(N);         N = 10;    checkIfCurzonNumber(N);}} // This code is contributed by coder001
# Python3 implementation of the approach # Function to check if a number# is a Curzon number or notdef 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 codeif __name__ == '__main__':         N = 5    checkIfCurzonNumber(N)     N = 10    checkIfCurzonNumber(N) # This code is contributed by mohit kumar 29
// C# implementation of the approachusing System; class GFG{     // Function to check if a number// is a curzon number or notstatic 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 codestatic public void Main (){    long N = 5;    checkIfCurzonNumber(N);         N = 10;    checkIfCurzonNumber(N);}} // This code is contributed by shubhamsingh10
<script> // Javascript implementation of the approach // Function to check if a number// is a Curzon number or notfunction 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 codevar N = 5;checkIfCurzonNumber(N);     N = 10;checkIfCurzonNumber(N); // This code is contributed by Ankita saini    </script>
Yes
No
 
Time complexity: O(log N)
Auxiliary Space: O(1) 
mohit kumar 29
coder001
SHUBHAMSINGH10
ankita_saini
rishavmahato348
maths-power
Numbers
Mathematical
School Programming
Write From Home
Mathematical
Numbers
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Find all factors of a natural number | Set 1
Check if a number is Palindrome
Program to print prime numbers from 1 to N.
Program to add two binary strings
Fizz Buzz Implementation
Python Dictionary
Arrays in C/C++
Reverse a string in Java
Inheritance in C++
C++ Classes and Objects