20 lines
410 B
C
20 lines
410 B
C
#include <assert.h>
|
|
#include <stdio.h>
|
|
|
|
int threefourths(int x) {
|
|
int p = x >> 2, q = x & 3;
|
|
return p + (p << 1) + q + ((!q | (x >> 31)) & 1) - 1;
|
|
}
|
|
|
|
int main() {
|
|
int x = 0x88659612;
|
|
for (int i = 0; i < 100; i++) {
|
|
x++;
|
|
assert(threefourths(x) == (long long) x * 3 / 4);
|
|
}
|
|
x = 0x79642695;
|
|
for (int i = 0; i < 100; i++) {
|
|
x++;
|
|
assert(threefourths(x) == (long long) x * 3 / 4);
|
|
}
|
|
} |