#include <stdio.h>
#include <limits.h>
#define INT_BITS (sizeof(int)*8)
typedef struct div_result div_result;
struct div_result {
int quotient;
int remainder;
};
div_result divide(int dividend, int divisor) {
div_result result;
if (divisor == 0) {
result.quotient = dividend < 0 ? INT_MIN : INT_MAX;
result.remainder = 0;
return result;
}
if ((dividend == INT_MIN) && (divisor == -1)) {
result.quotient = INT_MAX;
result.remainder = 0;
return result;
}
int negative = (dividend < 0) ^ (divisor < 0);
if (dividend < 0) {
dividend = -dividend;
}
if (divisor < 0) {
divisor = -divisor;
}
int quotient = 0, remainder = 0;
for (int i = 0; i < sizeof(int)*8; i++) {
quotient <<= 1;
remainder <<= 1;
remainder += (dividend >> (INT_BITS - 1)) & 1;
dividend <<= 1;
if (remainder >= divisor) {
remainder -= divisor;
quotient++;
}
}
if (negative) {
result.quotient = -quotient;
result.remainder = -remainder;
} else {
result.quotient = quotient;
result.remainder = remainder;
}
return result;
}
int main() {
int dividend, divisor;
scanf("%i%i", ÷nd
, &divisor
);
div_result result = divide(dividend, divisor);
printf("%i %i\r\n", result.
quotient, result.
remainder); }
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxsaW1pdHMuaD4KCiNkZWZpbmUgSU5UX0JJVFMgKHNpemVvZihpbnQpKjgpCgp0eXBlZGVmIHN0cnVjdCBkaXZfcmVzdWx0IGRpdl9yZXN1bHQ7CnN0cnVjdCBkaXZfcmVzdWx0IHsKCWludCBxdW90aWVudDsKCWludCByZW1haW5kZXI7Cn07CgpkaXZfcmVzdWx0IGRpdmlkZShpbnQgZGl2aWRlbmQsIGludCBkaXZpc29yKSB7CglkaXZfcmVzdWx0IHJlc3VsdDsKCQoJaWYgKGRpdmlzb3IgPT0gMCkgewoJCXJlc3VsdC5xdW90aWVudCA9IGRpdmlkZW5kIDwgMCA/IElOVF9NSU4gOiBJTlRfTUFYOwoJCXJlc3VsdC5yZW1haW5kZXIgPSAwOwoJCXJldHVybiByZXN1bHQ7Cgl9CgkKCWlmICgoZ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