经过测试,符合条件的宿舍就只有这些了……多谢网上的答案让我AC……
#include <iostream>
#include <cmath>
#define N 9
using namespace std;
int prime[N] = {11, 23, 29, 37, 41, 43, 47, 53, 59};
void test(int p) {
long long bigN = pow(2, p) - 1;
long long tmp = bigN;
bool first = true, isCom = false;
for(long long i = 2; i * i <= tmp; i++) {
if(tmp % i) {
continue;
}
else {
if(first) {
cout << i;
first = false;
}
else {
cout << " * " << i;
}
tmp /= i;
i--;
isCom = true;
}
}
if(isCom) {
cout << " * " << tmp;
cout << " = " << bigN << " = ( 2 ^ " << p << " ) - 1" << endl;
}
}
int main() {
int n;
cin >> n;
for(int i = 0; i < N; i++) {
if(prime[i] <= n) {
test(prime[i]);
}
else {
break;
}
}
return 0;
}