zoukankan      html  css  js  c++  java
  • ural 1352. Mersenne Primes

    1352. Mersenne Primes

    Time limit: 1.0 second
    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 8thMersenne 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 12thone (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. Ndoesn’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

    inputoutput
    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值进行枚举

     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
    ",kiss[n]);
    25         T--;
    26     }
    27     return 0;
    28 }
    View Code
  • 相关阅读:
    Ubuntu系统下adb连接小米
    Android自动化测试工具 calabash-android
    Android
    Android单元测试——Instrumentation
    Linux C语言 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
    Sublime Text 2 配置
    转: N个Android很有用的代码片段
    图片测试脚本
    数据查找
    小小
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3403779.html
Copyright © 2011-2022 走看看