Ultraviolet A 1323-Vivian's problem (Mason prime number)

Source: Internet
Author: User

Link: Ultraviolet A 1323-Vivian's Problem

Given the number of N, add a power EI for each number, and the result of the N base multiplication is M. If the sum of all the factors of M can be written as 2x, returns the maximum value of X. If no conditions are met, no is output.

Solution: If a number can be written as the product of several different Mason prime numbers, the factor and the number can be written as 2x.
232? The range of 1 has only eight prime Mason numbers, so it can be processed by the pressure.

The prime number of Mason is a prime number in the form of 2 ^ I-1.

/********************** Mason prime number, (2 ^ K) -1 ** if a number can be divided into the product of several different Mason prime numbers, all the factors of the number and can be written in the form of 2 ^ n. * *********************/# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; typedef 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 ();} 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.