1352. Mersenne Primes
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Definition. If the number 2
N−1 is prime then it is called a
Mersenne prime number.
For example, 2
2−1 — the first Mersenne prime, 2
3−1 — the second Mersenne prime, 2
11213−1 — the 23
rd, 2
216091−1 — the 31
st.
It’s a hard problem to find those numbers without a computer. So, Euler in 1772 found the 8
thMersenne prime — 2
31−1 and then for 100 years no Mersenne prime was found! Just in 1876 Lucas showed that 2
127−1 is a prime number. But he didn’t find the 9
th Mersenne prime, it was the 12
thone (the numbers 2
61−1, 2
89−1 and 2
107−1 are prime but it was found out later). A new break-through happened only in 1950’s when with the help of the computing machinery Mersenne primes with the powers 521, 607, 1279, 2203 and 2281 were found. All the following Mersenne primes were found with the help of computers. One needn’t be a great mathematician to do that. In 1978 and 1979 students Noll and Nickel found the 25
th and 26
th numbers (21701 and 23209) on the mainframe of their University and they became famous all over the USA. But the modern supercomputers have the limits of their capability. Today the dozens of thousands people all over the world united in one metaproject GIMPS (Great Internet Mersenne Prime Search, www.mersenne.org) look for Mersenne primes. GIMPS found 8 the greatest Mersenne primes. Their powers are 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583, 25964951. 2
6972593−1 is the 38
th Mersenne prime, and for the last 4 numbers one can’t tell what are their sequence numbers because not all the lower numbers are checked. Those four numbers are also the greatest known prime numbers.
The latest number 2
25964951−1 was found on February 18, 2005, it contains 7816230 decimal digits. The one who will find a prime number with more than 10 millions digits will get a prize of $100000. You may gain the prize if you join the project.
You are not now to find the 43
th Mersenne prime — the jury won’t be able to check your answer.
Ndoesn’t exceed 38 in this problem. So, given an integer
N you are to find
N
th Mersenne prime.
(Information is actual for March, 2005)
Input
The first line contains integer
T — an amount of tests. Each of the next
T lines contains an integer
N.
Output
For each
N you should output the power of the
N
th by order Mersenne prime.
Sample
input | output |
---|---|
13 18 32 24 21 19 34 27 33 20 30 28 29 22 | 3217 756839 19937 9689 4253 1257787 44497 859433 4423 132049 86243 110503 9941 |
题意:梅森素数:m=2^p-1,如果m是素数,则m被称为梅森素数,题意要求求出第i个梅森素数所对应的p的值
思路;梅森素数现在一共有43个,我们将他们所有的所对应的p值进行枚举
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<string> 7 8 9 using namespace std; 10 11 int kiss[]={0,2,3,5,7,13,17,19,31,61,89, 12 107,127,521,607,1279,2203,2281,3217,4253,4423, 13 9689,9941,11213,19937,21701,23209,44497,86243,110503,132049, 14 216091,756839,859433,1257787,1398269,2976221,3021377,6972593}; 15 16 17 int main() 18 { 19 int T; 20 scanf("%d",&T); 21 while(T){ 22 int n; 23 scanf("%d",&n); 24 printf("%d\n",kiss[n]); 25 T--; 26 } 27 return 0; 28 }