Advertisement
pasholnahuy

Untitled

Dec 24th, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <inttypes.h>
  2. #include <stdio.h>
  3.  
  4. enum { CONST = 0b1010101010101011 };
  5.  
  6. uint16_t add(uint16_t x, uint16_t y) {
  7. if (y == 0) {
  8. return x;
  9. }
  10. return add(x ^ y, (x & y) << 1);
  11. }
  12.  
  13. uint64_t mul(uint16_t x, uint16_t div_const, uint16_t cur_deg) {
  14. if (div_const & 1) {
  15. return add(mul(x, div_const >> 1, add(cur_deg, 1)), (x << cur_deg));
  16. }
  17. if (div_const == 0) {
  18. return 0;
  19. }
  20. return mul(x, div_const >> 1, add(cur_deg, 1));
  21. }
  22.  
  23. int main() {
  24. uint16_t n;
  25. if (scanf("%hu", &n) == 1) {
  26. uint64_t mul_n = mul(n, CONST, 0);
  27. printf("%" PRIu64, mul_n);
  28. printf("\n");
  29. // uint16_t mul_n = mul(n, 3, 0);
  30. // printf("%hu ", mul_n);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement