#include #include #include #include #include using namespace std; int Base(long int a) { int i = 0; while (a > 0) { a = a / 10; i++; cout << endl << i; } cout << endl <<"Тут должен быть 0 : " << a; return i; } int Naitive_Multyply(int a, int b) { int c = a * b; return c; } int Multyply(int base, int a, int b) { int b0, b1, a0, a1; int n = (pow(10, base / 2)); a1 = a / pow(10, base / 2); a0 = a % n; int n2 = (pow(10, base / 2)); b1 = b / pow(10, base / 2); b0 = b % n2; int c1, c2, c0; if (Base(a1) <= 2) { c2 = Naitive_Multyply(a1,b1); c0 = Naitive_Multyply(a0, b0); c1 = Naitive_Multyply(a1+a0, b1+b0) - (c2 + c0); } else { if (base % 2 != 0) base++; c2 = Multyply(base/2,a1, b1); c0 = Multyply(base/2,a0, b0); c1 = Multyply(base/2,a1 + a0, b1 + b0) - (c2 + c0); } int c = c2 * (unsigned long int)(pow(10, base)) + c1 * pow(10, base / 2) + c0; return c; } int main() { setlocale(0, ""); long int a; cout << "Введите число 1: "; cin >> a; int base = 0; int base_a; base_a = Base(a); cout << "Количество цифр числа 1 = " << base_a; cout << endl; int b; cout << "Введите число 2: "; cin >> b; int base_b; base_b = Base(b); cout << "Количество цифр числа 2 = " << base_b; cout << endl; if (base_a < 2 && base_b < 2) cout << endl << "Результат умножения : " << Naitive_Multyply(a, b) << endl; else { if (base_a != base_b) { int base_temp = abs(base_a - base_b); if (a < b) { a *= pow(10, (base_temp)); base = base_b; } else b *= pow(10, (base_temp)); base = base_a; cout << endl << Multyply(base, a, b) / pow(10, (base_temp)); } else if (base_a == base_b) { base = base_b; cout << endl << "Результат умножения : " << Multyply(base, a, b) << endl; } } system("pause"); return 0; }