FUNCTION
multiply
Performs the multiplication of two long positive integers in the given base.
You're viewing an older version of this page (#231). View the current version.
Interface
#include <codecogs/maths/combinatorics/arithmetic/multiply.h>
using namespace Maths::Combinatorics::Arithmetic;
This function calculates the multiplication of two long <em> positive </em> integers stored as character strings, in the given numerical base. The maximum number of digits of either the numbers is only limited by the amount of memory available. The algorithm used is school multiplication and has time complexity
(1)
where is the length (number of digits) of a and
is the length of b.
Example:
#include <codecogs/maths/arithmetic/multiply.h>
#include <iostream>
int main()
{
std::string a("77723445"), b("1236174734675"),
c = Maths::Arithmetic::multiply(a, b, 8);
std::cout << "The following is a base 8 operation" << std::endl;
std::cout << a << " * " << b << " = " << c << std::endl;
return 0;
}
Output:
The following is a base 8 operation
77723445 * 1236174734675 = 123525352137151621521
Parameters
a
the first factor
b
the second factor
base
Default value = 10
Returns
a character string corresponding to the multiplication of the given numbers
Interactive Calculator
a
b
base
Result
Computing…
Set a range above first to export a graph.
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.