Topic Link: UVa 1323-vivian ' s Problem
Given the number of N, and then add a power ei for each number, the last N-term base multiplication of the result is m, if the sum of all the factors of M can be written as 2x, to find the maximum value of x, if there is no condition to meet, output no
How to solve a problem: If a number can be written as a product of several different Mason primes, then the number of factors and can be written as 2x.
The range of 232−1 is only 8 primes, so it can be treated with a form of pressure.
The prime number of a Mason is a 2^i-1 form.
/********************** * Mason Prime number, (2^k)-1 * * A number if the difference is divided into a number of different numbers of the product of the Mason, then all the factors and can be written in 2^n form. * **********************/#include <cstdio> #include <cstring> #include <algorithm> using namespace St
D
typedef long Long LL;
const int MAXP = 8;
const int F[MAXP+5] = {2, 3, 5, 7, 13, 17, 19, 31};
int N, ans, s[105];
ll Mpri[maxp+5];
void insert (ll u) {s[n] = 0;
for (int i = 0; i < Maxp i++) {if (u% mpri[i] = = 0) {S[n] |= (1<<i);
U/= Mpri[i];
if (u% mpri[i] = = 0) return;
} if (U = = 1) n++;
int solve (int S) {int ret = 0;
for (int i = 0; i < MAXP i++) if (s& (1<<i)) ret = F[i];
return ret;
void Dfs (int d, int S) {ans = max (ans, solve (s));
for (int i = D; i < N; i++) if ((s&s[i]) = = 0) dfs (i+1, s|s[i)); int main () {for (int i = 0; i < MAXP i++) mpri[i] = (1ll<<f[i])-1;
ll N, A;
while (scanf ("%lld", &n) = = 1) {n = 0;
for (int i = 0; i < n; i++) {scanf ("%lld", &a);
Insert (a);
} if (N = = 0) printf ("no\n");
else {ans = 0;
DFS (0, 0);
printf ("%d\n", ans);
} return 0; }