代码
#include <bits/stdc++.h>
using namespace std;
int t;
bool zs(int h) {
for (int i = 2; i * i <= h; i++) {
if (h % i == 0)
return 0;
}
return 1;
}
int main() {
cin >> t;
while (t--) {
int h, w, l = 0, cnt = 1, cnt1 = 1;
cin >> h;
w = h;
if (zs(w)) {
cout << 1 << endl;
continue;
}
int j = 1;
while (w != 0) {
if (w < 0) {
break;
}
cnt++;
w -= int(pow(2, j - 1));
j++;
}
if (w == 0) {
cout << cnt << endl;
continue;
}
while (!zs(h)) {
h--;
l++;
}
int i = 1;
bool s = 1;
while (l != 0) {
if (l < 0) {
cout << -1 << endl;
s = 0;
break;
}
cnt1++;
l -= int(pow(2, i - 1));
i++;
}
if (s) {
cout << cnt1 << endl;
}
}
return 0;
}
测点