Title Description
Description
The prime number of a shape such as 2p-1 is called Mason, at which point P must also be a prime. But not necessarily, that is, if p is a prime number, 2p-1 is not necessarily a prime number. By the end of 1998, 37 Mason had been found. The biggest one is p=3021377, which has 909,526 bits. Mason number has many important applications, which are closely related to the complete number.
Task: Enter P (1000<p<3100000) from the file to calculate the number of digits of 2p-1 and the last 500 digits (expressed in decimal high precision number)
Enter a description
Input Description
Only one integer P (1000<p<3100000) is included in the file
Output description
Output Description
First line: Decimal high precision number 2P-1 digits.
第2-11 line: Decimal High precision number 2P-1 the last 500 digits. (output 50 bits per line, output 10 lines, less than 500 bits when the high 0)
You do not have to verify that 2p-1 and p are prime numbers.
Sample input
Sample Input
1279
Sample output
Sample Output
386
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000104079321946643990819252403273640855
38615262247266704805319112350403608059673360298012
23944173232418484242161395428100779138356624832346
49081399066056773207629241295093892203457731833496
61583550472959420547689811211693677147548478866962
50138443826029173234888531116082853841658502825560
46662248318909188018470682222031405210266984354887
32958028878050869736186900714720710555703168729087
Data range and Tips
Data Size & Hint
Exercises
High precision + number theory + two points.
Use the formula: 2 (Y) =sqr (2 (Y Div 2)), if Y is an even number without tube, if y is odd, then multiply 2. Formula for the number of digits (2 (y)): Trunc (log10 (2) *y) +1 (log10 function in math Math library).
Uses math;
var i,p:longint;
A,c:array[0..2001]of Longint;
Procedure F (k:longint);
var i,j:longint;
Begin
If K=0 then exit;
F (k Div 2);
Fillchar (C,sizeof (c), 0);
For I:=1 to A[0] do
For J:=1 to A[0] do
Begin
Inc (C[i+j-1],c[i+j-2] Div 10+a[i]*a[j]);
C[I+J-2]:=C[I+J-2] MoD 10;
End
c[0]:=a[0]*2-1;
While c[c[0]]>9 do
Begin
C[c[0]+1]:=c[c[0]] Div 10;
C[C[0]]:=C[C[0]] MoD 10;
Inc (C[0]);
End
A:=c;
If c[0]>500 then a[0]:=500;
If k mod 2=0 then exit;
Fillchar (C,sizeof (c), 0);
For I:=1 to A[0] do
Begin
C[i]:=a[i]*2+c[i-1] Div 10;
C[I-1]:=C[I-1] MoD 10;
End
C[0]:=A[0];
While c[c[0]]>9 do
Begin
C[c[0]+1]:=c[c[0]] Div 10;
C[C[0]]:=C[C[0]] MoD 10;
Inc (C[0]);
End
A:=c;
If c[0]>500 then a[0]:=500;
End
Begin
READLN (P);
Writeln (Trunc (log10 (2) *p) +1);
A[0]:=1;
A[1]:=1;
f (P);
Dec (a[1]);
For i:=500 Downto 1 do
if (i mod 50=1) then Writeln (A[i])
else write (a[i]);
End.
2003 Mason Number