高精度乘法模板
本文最后更新于 1160 天前,其中的信息可能已经有所发展或是发生改变。

高精度乘低精度

#include<iostream>
 #include<vector>
 using namespace std;
 vector<int> mul(vector<int> &A,int b)
 {
     vector<int> C;
     for(int i=0,t=0;i<A.size()||t;i++)
     {
         if(i<A.size())  t+=A[i]*b;
         C.push_back(t%10);
         t/=10;
     }
     while(!C.back()&&C.size()) C.pop_back();
     return C;
 }
 int main()
 {
     string a;
     int b;
     vector<int> A,B;
     cin>>a>>b;
     for(int i=a.length()-1;i>=0;i--)    A.push_back(a[i]-'0');
     vector<int> C=mul(A,b);
     for(int i=C.size()-1;i>=0;i--)  cout<<C[i];
     return 0;
 }

高精度乘高精度

 #include<iostream> #include<vector>
 using namespace std;
 vector<int> mul(vector<int> &A,vector<int> &B)
 {
     vector<int> C(A.size()+B.size());
     for(int i=0;i<A.size();i++)
         for(int j=0;j<B.size();j++)
         {
             C[i+j]+=A[i]*B[j];
             C[i+j+1]+=C[i+j]/10;
             C[i+j]%=10;
         }
     while(!C.back()&&C.size()>1) C.pop_back();
     return C;
 }
 int main()
 {
     string a,b;
     vector<int> A,B;
     cin>>a>>b;
     for(int i=a.length()-1;i>=0;i--)    A.push_back(a[i]-'0');
     for(int i=b.length()-1;i>=0;i--)    B.push_back(b[i]-'0');
     vector<int> C=mul(A,B);
     for(int i=C.size()-1;i>=0;i--)  cout<<C[i];
     return 0;
 }
转载请注明出处!本文链接: https://battlehawk233.cn/post/54.html



暂无评论

发送评论编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇