Advertisement
Plabon_dutta

UVA 10940 - Throwing cards away II

Jun 5th, 2021
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.27 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int f(int n) {
  4.     if(n <= 1)
  5.         return 1;
  6.     if(n&1)
  7.         return (f((n+1)/2)-1)*2;
  8.     else
  9.         return f(n/2)*2;
  10. }
  11. int main() {
  12.     int n;
  13.     while(scanf("%d", &n) == 1 && n) {
  14.         printf("%d\n", f(n));
  15.     }
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement