I have seen many answers here and on the internet but i don't need a big int library, I need a program that multiplies big numbers in c++/c but really fast, I have tried different prorgams and some of them are not runing really fast, so please help me with this multiplication problem, thanks.
Here is what i have tried, it is good, but not very fast. It works, but not for numbers that have 1000 digits, please help me:
#include<iostream>
#include<fstream>
#include<string.h>
#define MAX 300000
using namespace std;
ifstream fin("test.in");
ofstream fout("test.out");
void reverse(char *from, char *to ){
int len=strlen(from);
int l;
for(l=0;l<len;l++)to[l]=from[len-l-1];
to[len]='\0';
}
void mult(char *first,char *sec,char *result){
char F[MAX],S[MAX],temp[MAX];
int f_len,s_len,f,s,r,t_len,hold,res;
f_len=strlen(first);
s_len=strlen(sec);
reverse(first,F);
reverse(sec,S);
t_len=f_len+s_len;
r=-1;
for(f=0;f<=t_len;f++)temp[f]='0';
temp[f]='\0';
for(s=0;s<s_len;s++){
hold=0;
for(f=0;f<f_len;f++){
res=(F[f]-'0')*(S[s]-'0')+hold+(temp[f+s]-'0');
temp[f+s]=res%10+'0';
hold=res/10;
if(f+s>r)r=f+s;
}
while(hold!=0){
res=hold+temp[f+s]-'0';
hold=res/10;
temp[f+s]=res%10+'0';
if(r<f+s)r=f+s;
f++;
}
}
for(;r>0 && temp[r]=='0';r--);
temp[r+1]='\0';
reverse(temp,result);
}
int main(){
char fir[MAX],sec[MAX],res[MAX];
int m,n;
fin>>m>>fir;
n=strlen(fir);
for(int i=0;i<n;i++)sec[i]=fir[i];
for(int i=1;i<m;i++)
{
mult(fir,sec,res);
int len=strlen(res);
if(i<m-1)
for(int j=0;j<len;j++)fir[j]=res[j];
else for(int j=0;j<len;j++)fout<<res[j];
}
return 0;
}