[Sicily online] 1009. Mersenne composite n

Source: Internet
Author: User
/* Restrictions on the shift operation constraintstime limit: 1 secs, memory limit: 32 mbdescriptionone of the world-wide cooperative computing tasks is the "Grand Internet Mersenne prime search" -- gimps -- striving to find ever-larger prime numbers by examining a particle category of such numbers. A Mersenne number is defined as a number of the form (2p-1), where p is a prime number -- a number divisible only by one and its Elf. (a number that can be divided by numbers other than itself and one are called "composite" numbers, and each of these can be uniquely represented by the prime numbers that can be multiplied together to generate the composite number-referred to as its prime factors .) initially it looks as though the Mersenne numbers are all Primes. primecorresponding Mersenne Number24-1 = 3 -- prime38-1 = 7- -Prime532-1 = 31 -- prime7128-1 = 127 -- primeif, however, we are having a "grand Internet" search, that must not be the case. where k is an input parameter, compute all the Mersenne composite numbers less than 2 k -- where k <= 63 (that is, it will fit in a 64-bit signed integer on the computer ). in Java, the "long" data type is a signed 64 bit integer. under GCC and G ++ (C and C ++ in the program Ming contest Environment), the "long" data type is a signed 64-bit integer. inputinput is from File. in. it contains a single number, without leading or trailing blanks, giving the value of K. as promised, k <= 63. outputone line per Mersenne composite number giving first the prime factors (in increasing order) separate by asterisks, an equal sign, the Mersenne number itself, an equal sign, Nd then the explicit statement of the Mersenne number, as shown in the sample output. use exactly this format. note that all separating white space fields consist of one blank. sample input31sample output23 * 89 = 2047 = (2 ^ 11)-147*178481 = 8388607 = (2 ^ 23)-1233*1103*2089 = 536870911 = (2 ^ 29) -1 */# include <iostream> # include <iomanip> # include <stdio. h> # include <cmath> # include <IOM ANIP> # include <list> # include <map> # include <vector> # include <string> # include <algorithm> # include <sstream> # include <stack> # include <queue> # include <string. h> using namespace STD; bool CAL (unsigned long number, vector <unsigned long> & factor) {for (unsigned long I = 3; I <= SQRT (double) number); I + = 2) {If (Number % I = 0) {factor. push_back (I); If (! Cal (number/I, factor) factor. push_back (number/I); Return true ;}} return false ;}int main () {int N; CIN >> N; For (INT I = 6; I <N; I ++) {bool flag = false; For (Int J = 2; j <= SQRT (double) I); j ++) {if (I % J = 0) Flag = true;} If (FLAG) continue; unsigned long number = POW (2.0, I)-1; // The shift operation can only contain 31-bit vector <unsigned long> factor; CAL (number, factor); sort (factor. begin (), factor. end (); If (factor. size () <2) continue; For (vector <unsigned long >:: size_type J = 0; j <factor. size ()-1; j ++) cout <factor [J] <"*"; cout <factor [factor. size ()-1] <"=" <number <"= (2 ^" <I <")-1" <Endl ;}}

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.