//404K  0MS G++
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

// bool isPrime(long long N) {
//     for (long long i = 2; i <= N/2+1; i++) {
//         if (N%i == 0) {
//             return 0;
//         }
//     }
//     return 1;
// }

// void preprocess() {
//     long long val = 4;
//     for (int i = 2; i <= 63; i++) {
//         if (isPrime(i)) {        
//             if (!isPrime(val - 1)) {
//                 long long curVal = val - 1;
//                 printf("(2^%d) - 1\n", i);
//                 long long leftPart = curVal;
//                 long long max = (long long)sqrt(leftPart);
//                 for (long long factor = 2; factor <= max; factor++) {
//                         <span style="color:#ff0000;">while (leftPart % factor == 0)
//                         {
//                             printf("%lld * ", factor);
//                             leftPart /= factor;
//                         }</span>
//                 }

//                 printf("%lld = %lld\n", leftPart, curVal);
//             }
//         }
//         val <<=1;
//     }
// }

// int main(int argc, char const *argv[])
// {
//     preprocess();
//     return 0;
// }

int main()
{
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]);

    return 0;
}


梅森素数,直接现离线求出所有满足条件的2k次方-1, 然后打表过了。 

有在线算法,不过太深了,不看了.