UVA 1323-vivian ' s Problem (Mason Prime) __ Mathematics-Number theory

Source: Internet
Author: User

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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.