#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <assert.h>
#include <thread>
#include <condition_variable>
#include <atomic>
#include <chrono>
using namespace std;
const int MAX_THREADS_COUNT = 8;
unsigned long m , n;
int* tVal;
void muladd(string const& a, string const& b, int flag) {
long pos = 0, value = 0;
for(long i=0; i< m; i++) {
if(i%MAX_THREADS_COUNT != flag) continue;
for(long j=0;j<n;j++) {
pos = (m - 1 - i) + (n - 1 - j);
value = (a.at(i) - '0') * (b.at(j) - '0');
tVal[pos] += value;
}
}
}
string mul(string a, string b) {
string res = "";
m = a.length();
n = b.length();
tVal = new int[m+n];
cout<<"m="<<m<<",n="<<n<<endl;
for(long i=0; i< m + n; i++) {
tVal[i] = 0;
}
std::thread* threads = new std::thread[m];
for(int i=0; i< MAX_THREADS_COUNT; i++) {
threads[i] = std::thread(muladd,a,b,i);
}
for(int i=0; i< MAX_THREADS_COUNT; i++)
threads[i].join();
cout<<"m + n="<<m + n<<endl;
for(long i=0; i< m + n; i++) {
if(tVal[i] > 9) {
tVal[i+1] += tVal[i]/10;
tVal[i] %= 10;
}
}
for(long i=m+n-1; i>=0; i--) {
if(tVal[i] == 0 && !res.compare("")) continue;
res += (tVal[i] + '0');
}
return res;
}
int main()
{
string a,b,c;
cin>>a>>b;
c=mul(a,b);
cout<<c<<endl;
return 0;
}
g++ -std=c++11 -pthread -o mul mul.cpp