1352. Mersenne Primes
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Definition. If the number 2N−1 is prime then it is called a Mersenne prime number.
For example, 22−1 — the first Mersenne prime, 23−1 — the second Mersenne prime, 211213−1 — the 23rd, 2216091−1 — the 31st.
It’s a hard problem to find those numbers without a computer. So, Euler in 1772 found the 8th Mersenne prime — 231−1 and then for 100 years no Mersenne prime was found! Just in 1876 Lucas showed that 2127−1 is a prime number. But he didn’t find the 9th Mersenne prime, it was the 12th one (the numbers 261−1, 289−1 and 2107−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 25th and 26th 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. 26972593−1 is the 38th
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 225964951−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 43th Mersenne prime — the jury won’t be able to check your answer. N doesn’t exceed 38 in this problem. So, given an integer N you are to find Nth 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 Nth 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
|
Problem Author: Vladimir Yakovlev
Problem Source: USU Junior Championship March'2005
没想到别的方法啊,只会打表了。。。
1 #include <iostream> 2 #include <sstream> 3 #include <fstream> 4 #include <string> 5 #include <vector> 6 #include <deque> 7 #include <queue> 8 #include <stack> 9 #include <set> 10 #include <map> 11 #include <algorithm> 12 #include <functional> 13 #include <utility> 14 #include <bitset> 15 #include <cmath> 16 #include <cstdlib> 17 #include <ctime> 18 #include <cstdio> 19 #include <string> 20 using namespace std; 21 int N, T; 22 const int M = 1e6+5; 23 bool a[M]; 24 int prime[M]; 25 int cnt = 0; 26 void init() { 27 for(int i = 2; i < M; i++) a[i] = true; 28 for(int i = 2; i < M; i++) { 29 if(a[i]) { 30 cnt++; 31 prime[cnt] = i; 32 } 33 for(int j = 1; j <= cnt; j++) { 34 if(i * prime[j] >= M) break; 35 a[i*prime[j]] = false; 36 if(i % prime[j] == 0) break; 37 } 38 } 39 } 40 int main() { 41 //freopen("in.txt", "r", stdin); 42 int a[] = {0,2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583, 25964951, 30402457, 32582657}; 43 int n; 44 scanf("%d", &n); 45 while(n--){ 46 int m; 47 scanf("%d", &m); 48 printf("%d ", a[m]); 49 } 50 return 0; 51 }