1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #include <iostream> #include <cstring> #include <algorithm> #include <cmath>
using namespace std;
#define SIGN(A) ((A > 0)?1:-1)
const int N = 110;
int x,y,n;
int mul(int x,int y,int n) { if(x == 0 || y == 0) return 0; if(n == 1) return x * y; int x1 = x/pow(10,n/2),y1 = y/pow(10,n/2); int x0 = x - x1 * pow(10,n/2),y0 = y - y1 * pow(10,n/2); int xy1 = mul(x1,y1,n/2),xy0 = mul(x0,y0,n/2),xy10 = mul(x1-x0,y0-y1,n/2); return xy1 * pow(10,n) + (xy10 + xy0 + xy1) * pow(10,n/2) + xy0; }
int main(){ cin >> x >> y >> n; int s = SIGN(x) * SIGN(y); int res = s * mul(abs(x),abs(y),n); cout << res; return 0; }
|