POJ 2191 梅森素数

/*

梅森素数:若 2^p - 1 是一个素数,则 p 就是梅森素数,前几个有:2 3 5 7 13 17 19 31.... 

非打表算法神牛博客:http://www.cnblogs.com/tmeteorj/archive/2012/10/02/2710444.html

唉,我是打表过的...非打表的不知道错了几会...

题意:判断所有质数i<=k,2^i-1是否是质数,不是的话就要将它分解质因数输出来。

*/

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    
 string s1="23 * 89 = 2047 = ( 2 ^ 11 ) - 1";
 string s2="47 * 178481 = 8388607 = ( 2 ^ 23 ) - 1";
 string s3="233 * 1103 * 2089 = 536870911 = ( 2 ^ 29 ) - 1";
 string s4="223 * 616318177 = 137438953471 = ( 2 ^ 37 ) - 1";
 string s5="13367 * 164511353 = 2199023255551 = ( 2 ^ 41 ) - 1";
 string s6="431 * 9719 * 2099863 = 8796093022207 = ( 2 ^ 43 ) - 1";
 string s7="2351 * 4513 * 13264529 = 140737488355327 = ( 2 ^ 47 ) - 1";
 string s8="6361 * 69431 * 20394401 = 9007199254740991 = ( 2 ^ 53 ) - 1";
 string s9="179951 * 3203431780337 = 576460752303423487 = ( 2 ^ 59 ) - 1";
    int k;
    while(cin>>k){
        if(k>=11&&k<=22) cout<<s1<<endl;
        if(k>=23&&k<=28) cout<<s1<<endl<<s2<<endl;
        if(k>=29&&k<=36) cout<<s1<<endl<<s2<<endl<<s3<<endl;
        if(k>=37&&k<=40) cout<<s1<<endl<<s2<<endl<<s3<<endl<<s4<<endl;
        if(k>=41&&k<=42) cout<<s1<<endl<<s2<<endl<<s3<<endl<<s4<<endl<<s5<<endl;
        if(k>=43&&k<=46) cout<<s1<<endl<<s2<<endl<<s3<<endl<<s4<<endl<<s5<<endl<<s6<<endl;
        if(k>=47&&k<=52) cout<<s1<<endl<<s2<<endl<<s3<<endl<<s4<<endl<<s5<<endl<<s6<<endl<<s7<<endl;
        if(k>=53&&k<=58) cout<<s1<<endl<<s2<<endl<<s3<<endl<<s4<<endl<<s5<<endl<<s6<<endl<<s7<<endl<<s8<<endl;
        if(k>=59&&k<=63) cout<<s1<<endl<<s2<<endl<<s3<<endl<<s4<<endl<<s5<<endl<<s6<<endl<<s7<<endl<<s8<<endl<<s9<<endl;
    }
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值