High-precision multiplication

Source: Internet
Author: User

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

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.