The Wayback Machine - https://web.archive.org/web/20240627104139/https://www.geeksforgeeks.org/gfact-22-2x-1-prime/
Open In App

GFact | 2x + 1(where x > 0) is prime if and only if x is a power of 2

Last Updated : 17 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

A number of the form 2x + 1 (where x > 0) is prime if and only if x is a power of 2, i.e., x = 2n. So overall number becomes 22n + 1. Such numbers are called Fermat Number (Numbers of form 22n + 1). The first few Fermat numbers are 3, 5, 17, 257, 65537, 4294967297, …. An important thing to note is a number of the form 22n + 1) is not always prime. For example 225 + 1 = 25 + 1 = 232 + 1 = 4294967297 = 641 * 6700417. This fact is contributed by Shivam Pradhan (anuj_charm).


Previous Article
Next Article

Similar Reads

Find power of power under mod of a prime
Given four numbers A, B, C and M, where M is prime number. Our task is to find ABC (mod M).Example: Input : A = 2, B = 4, C = 3, M = 23 Output : 6 43 = 64 so, 2^64(mod 23) = 6 A Naive Approach is to calculate res = BC and then calculate Ares % M by modular exponential. The problem of this approach is that we can't apply directly mod M on BC, so we
7 min read
GFact | Why Printing Boolean in C++ Display as 0 and 1
Have you ever tried to print some boolean value in the cout section of your code? If yes, then you must have got the output as 0 or 1. But what hapenned to the Boolean value? Why didn't it got printed in the first place? How to get print the boolean value as it is in the output section? What happens when printing Boolean value in C++?Consider the f
2 min read
GFact | 6 Digit number always divisible by 7, 11 and 13 when formed by repeating a 3-digit number twice
The statement "If we repeat a three-digit number twice, to form a six-digit number, the result will be divisible by 7, 11, and 13" is a mathematical property in number theory and mathematics. By repeating a three-digit number twice, we get a six-digit number having the last three digits the same as the first three digits. The number formed is divis
3 min read
GFact | Which Sorting Algorithm is Best and Why?
A sorting algorithm is an algorithm that makes the input data set arranged in a certain order. The fundamental task is to put the items in the desired order so that the records are re-arranged for making searching easier. Which is the best sorting algorithm?Quicksort is one of the most efficient sorting algorithms, and this makes of it one of the m
3 min read
GFact | How to construct Binary Tree and Binary Search Trees?
To uniquely construct a Binary Tree, Inorder together with either Postorder or Preorder must be given (See this for details). However, either Postorder or Preorder traversal is sufficient to uniquely construct a Binary Search Tree. To construct Binary Search tree, we can get Inorder traversal by sorting the given Preorder or Postorder traversal. So
1 min read
GFact | Pointer arithmetic and array indexing are equivalent in C
"Pointer arithmetic and array indexing [that] are equivalent in C, pointers and arrays are different" - Wayne Throop References: http://c-faq.com/aryptr/aryptrequiv.html
1 min read
GFact | C standard C99 allows inline functions and variable-length-arrays
The C standard C99 allows inline functions and variable-length-arrays. So following functions are valid in C99 compliant compilers. Example for inline functions inline int max(int a, int b) { if (a > b) return a; else return b; } a = max (x, y); /* This is now equivalent to if (x > y) a = x; else a = y; */ Example for variable length arrays f
1 min read
GFact | Difference between Pass by value and Pass-by-reference in C
In C, function parameters are always passed by value. Pass-by-reference is simulated in C by explicitly passing pointer values.
1 min read
GFact | Use of struct keyword in C and C++
In C, struct keyword must be used for declaring structure variables, but it is optional in C++. For example, following program gives error in C and works in C++. struct node { int x; node *next; // Error in C, struct must be there. Works in C++ }; int main() { node a; // Error in C, struct must be there. Works in C++ } And following program works i
1 min read
GFact | const Behaviour in C and C++
const Behaviour in C and C++ In C, the const qualified identifiers will have external linkage, where as in C++ it will have internal linkage. For example, In C++, the following statement is implicitly defined as i.e. the scope of interest_rate is limited to the block in which it is defined. In C, the above statement will have external linkage when
1 min read
Article Tags :
Practice Tags :