26 lines
460 B
C

#include <assert.h>
#include <limits.h>
#include <stdlib.h>
int threefourths(int x) {
int p = x >> 2, q = x & 3;
return p + (p << 1) + q - ((!!q & (~x >> 31)) & 1);
}
int randi() {
if (rand() & 1) {
return rand();
} else {
return ~rand();
}
}
int main() {
assert(RAND_MAX == INT_MAX);
const int test_cases = 1e8;
for (int i = 0; i < test_cases; i++) {
int x = randi();
assert(threefourths(x) == (long long) x * 3 / 4);
}
}