Sicily 1009. Mersenne composite n

Source: Internet
Author: User
Descriptionone 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 special 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 itself. (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.
Prime Corresponding Mersenne number
2 4-1 = 3 -- prime
3 8-1 = 7 -- prime
5 32-1 = 31 -- prime
7 128-1 = 127 -- prime

If, 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 programming 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, and 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 input copy sample input to clipboard
31
Sample output
23 * 89 = 2047 = ( 2 ^ 11 ) - 147 * 178481 = 8388607 = ( 2 ^ 23 ) - 1233 * 1103 * 2089 = 536870911 = ( 2 ^ 29 ) - 1

 

// Specify a number K, evaluate the number P smaller than K and 2 ^ p-1 is the prime factor of the number of a sum # include <iostream> # include <cmath> using namespace STD; int main (INT argc, char * argv []) {int num; CIN> num; int P [10] = {11, 23, 29, 37, 41, 43, 47, 53, 59}; For (INT I = 0; I! = 10 & P [I] <num; ++ I) {long result = static_cast <long> (POW (2, P [I])-1; long long temp = result; long factor = 2; bool flag = false; while (factor * factor <result) {If (result % factor = 0) {flag = true; result/= factor; cout <factor <"*";} else {factor ++;} If (FLAG) cout <result <"=" <temp <"= (2 ^" <p [I] <")-1" <Endl ;} return 0 ;}

 

Sicily 1009. Mersenne composite n

Related Article

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.