POJ 2191 梅森素數

來源:互聯網
上載者:User
/*梅森素數:若 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;    }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.