/*梅森素數:若 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; }}