zoukankan      html  css  js  c++  java
  • poj2191

    题意:梅森数(Mersenne number)是指形如2^p-1的正整数,其中指数p是素数,常记为Mp 。若Mp是素数,则称为梅森素数(Mersenne prime)。

    本题要求梅森合数。

    分析:

    打表计算,求出所有的梅森数,并暴力分解,看是否为合数。

    View Code
    /*
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    using namespace std;

    bool isprime(int a)
    {
    for (int i = 2; i < a; i++)
    if (a % i == 0)
    return false;
    return true;
    }

    int main()
    {
    freopen("t.txt", "r", stdin);
    for (int i = 32; i <= 59; i++)
    if (isprime(i))
    {
    long long k = 1;
    k <<= i;
    k--;
    long long t = (long long) sqrt(k);
    for (long long j = 2; j <= t; j++)
    {
    while (k % j == 0)
    {
    printf("%lld * ", j);
    k /= j;
    }
    }
    if (k != 1)
    printf("%lld", k);
    k = 1;
    k <<= i;
    k--;
    printf(" = %lld = ( 2 ^ %d ) - 1\n", k, i);
    }
    return 0;
    }

    */
    #include
    <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    usingnamespace std;

    int main()
    {
    //freopen("t.txt", "r", stdin);
    int f[10] =
    {
    11, 23, 29, 37, 41, 43, 47, 53, 59 };
    char st[10][100] =
    {
    "23 * 89 = 2047 = ( 2 ^ 11 ) - 1",
    "47 * 178481 = 8388607 = ( 2 ^ 23 ) - 1",
    "233 * 1103 * 2089 = 536870911 = ( 2 ^ 29 ) - 1",
    "223 * 616318177 = 137438953471 = ( 2 ^ 37 ) - 1",
    "13367 * 164511353 = 2199023255551 = ( 2 ^ 41 ) - 1",
    "431 * 9719 * 2099863 = 8796093022207 = ( 2 ^ 43 ) - 1",
    "2351 * 4513 * 13264529 = 140737488355327 = ( 2 ^ 47 ) - 1",
    "6361 * 69431 * 20394401 = 9007199254740991 = ( 2 ^ 53 ) - 1",
    "179951 * 3203431780337 = 576460752303423487 = ( 2 ^ 59 ) - 1" };
    int n;
    scanf(
    "%d", &n);
    for (int i =0; i <9; i++)
    if (f[i] <= n)
    printf(
    "%s\n", st[i]);

    return0;
    }
  • 相关阅读:
    interface in iOS
    iOS Crash 分析 符号化崩溃日志
    获取IMSI
    nmon 命令
    nmon监控Linux服务器系统资源
    ios tcpdump
    svn Previous operation has not finished; run 'cleanup' if it was interrupted
    build dynamic libraries for iOS and load them at runtime
    ADO:连接,执行语句与关闭(sql server数据库)
    QFileInfo与QFileIconProvider(分别用于获取文件信息和获取文件的图标)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2111206.html
Copyright © 2011-2022 走看看