Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <inttypes.h>
- #include <stdio.h>
- enum { CONST = 0b1010101010101011 };
- uint16_t add(uint16_t x, uint16_t y) {
- if (y == 0) {
- return x;
- }
- return add(x ^ y, (x & y) << 1);
- }
- uint64_t mul(uint16_t x, uint16_t div_const, uint16_t cur_deg) {
- if (div_const & 1) {
- return add(mul(x, div_const >> 1, add(cur_deg, 1)), (x << cur_deg));
- }
- if (div_const == 0) {
- return 0;
- }
- return mul(x, div_const >> 1, add(cur_deg, 1));
- }
- int main() {
- uint16_t n;
- if (scanf("%hu", &n) == 1) {
- uint64_t mul_n = mul(n, CONST, 0);
- printf("%" PRIu64, mul_n);
- printf("\n");
- // uint16_t mul_n = mul(n, 3, 0);
- // printf("%hu ", mul_n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement