Fourth session Waterloo Cup a group of java--Mason primes

Source: Internet
Author: User
Package the_fourth_session_a;

/*
Title: Mason Prime
If the sum of all the true factors of a number equals itself, it is called "complete number" or "perfect number".
For example: 6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
As early as more than 300 BC, Euclid gave a theorem to determine the complete number:
If the 2^n-1 is prime, then 2^ (n-1) * (2^n-1) is the complete number.
where ^ denotes "exponentiation" operation, the precedence of the powers is higher than arithmetic, for example: 2^3 = 8, 2 * 2^3 = 16, 2^3-1 = 7
But people quickly find that when n is very large, deciding whether a large number is prime is still a problem today.
Because the French mathematician Mason's conjecture, we are accustomed to the shape such as: 2^n-1 prime number is called: Mason Prime.
As of February 2013, only 48 Mason primes were found. The newly found Mason primes are so large that it is difficult to see the whole picture with general programming ideas, so we reduce the difficulty of the task by a little:
In 1963, the University of Illinois in the United States, in honor of the 23rd Mason Prime n=11213 They found, printed the words "2^11213-1 is prime" on each envelope sent.
2^11213-1 This number is already very large (there are more than 3,000), please program to find the decimal representation of the last 100 digits of this prime.
The answer is a numeric string of 100 length, please submit the number directly through the browser.
Note: Do not submit the answer process, or the contents of other auxiliary instruction classes.


*/
Import java.math.*;
public class Meishengsushu
{
public static void Main (string[] args)
{
Generating large integer objects
BigInteger bn = new BigInteger ("2");

into the secondary cycle
for (int i = 1; i < 11213; i++)
{
bn = Bn.shiftleft (1);
}

Reduce the result by 1
BigInteger one = new BigInteger ("1");
bn = Bn.subtract (one);

Type conversions
String str = bn+ "";

Intercept the last 100 digits.
str = str.substring (str.length ()-100);

Output
System.out.println (str);
}

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