3117 multiplication of high-precision exercises
time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description
Description
Give two positive integers a and B to calculate the value of the a*b. Ensure that the number of digits A and B does not exceed 500 digits.
Enter a description
Input Description
Read in two positive integers separated by a space
Output description
Output Description
The value of the output a*b
Sample input
Sample Input
3 12
Sample output
Sample Output
36
Data range and Tips
Data Size & Hint
The number of digits of two positive integers is less than 500 bits
#include <iostream>#include<cstring>using namespacestd;inta[501],b[501],f[501],lena,lenb,lenc=1, X;Charn[501],m[501];intMain () {CIN>>N; CIN>>m; Lena=strlen (n); LenB=strlen (m); for(intI=0; i<lena; i++) A[lena-i]=n[i]-'0'; for(intI=0; i<lenb; i++) B[lenb-i]=m[i]-'0'; for(intI=1; i<=lena; i++) {x=0; for(intj=1; j<=lenb; J + +) {F[i+j-1]=a[i]*b[j]+x+f[i+j-1]; X=f[i+j-1]/Ten; F[i+j-1]%=Ten; } f[i+lenb]=x; } Lenc=lena+LenB; while(f[lenc]==0&&lenc>1) Lenc--; for(intI=lenc; i>=1; i--) cout<<F[i]; return 0;}
High-precision multiplication