Question 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 fileto calculate the number of digits of 2p-1 and the last 500 digits (expressed in decimal high precision number) |
Input |
Only one integer P (1000<p<3100000) is included in the file |
Output |
First line: Decimal high-precision number of digits 2p-1. 第2-11: The last 500 digits of the decimal high-precision number 2p-1. (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. |
Input example |
1279 |
Output example |
386 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000104079321946643990819252403273640855 38615262247266704805319112350403608059673360298012 23944173232418484242161395428100779138356624832346 49081399066056773207629241295093892203457731833496 61583550472959420547689811211693677147548478866962 50138443826029173234888531116082853841658502825560 46662248318909188018470682222031405210266984354887 32958028878050869736186900714720710555703168729087
|
|
I can still write high-precision!?!?!?
The first question with the mathematical solution, the second to write a multiplication, set a fast power on the line.
Mom I forgot to delete debugging, unexpectedly again T, this is the rhythm of the blacksmith?!?!?!
#include <cstdio>#include<cctype>#include<cmath>#include<cstring>#include<algorithm>#defineLC Ch[x][0]#defineRC Ch[x][1]#defineRep (s,t) for (int i=s;i<=t;i++)#defineren for (int i=first[x];i!=-1;i=next[i])using namespaceStd;inlineintRead () {intx=0, f=1;CharC=GetChar (); for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1; for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;}Const intmaxn=510;structBign {intLEN,S[MAXN]; Bign () {len=1; Fill (S,S+MAXN,0);} Bignoperator= (inta) {len=0; while(a) s[len++]=a%Ten, a/=Ten; } voidClean () { while(len>1&&!s[len-1]) len--;} voidprint () {intCnt=0; Rep (Len,499) s[i]=0; for(intI=499; i>=0; i--) {Putchar (S[i]+'0'); if(++cnt== -) cnt=0, Putchar ('\ n'); }} bignoperator* (Bign &b) {bign ans; Rep (0, len-1) for(intj=0; j<b.len;j++) if(i+j< -) ans.s[i+j]+=s[i]*B.s[j]; Ans.len=min (len+b.len+1, -); Rep (0, ans.len-1) ans.s[i+1]+=ans.s[i]/Ten, ans.s[i]%=Ten; Ans.clean (); returnans; }};voidPow (bign& ans,intN) {bign tmp;tmp=ans;n--; while(n) {if(n&1) ans=ans*tmp; TMP=tmp*tmp;n>>=1; }}intMain () {intn=read (); Bign Ans;ans=2;p ow (ans,n); ans.s[0]--;p rintf ("%d\n",int(LOG10 (2) *n) +1); Ans.print (); return 0;}
View Code
NOIP200304 Mason Number