Skip to content

Instantly share code, notes, and snippets.

@trhgquan
Created October 15, 2019 12:53
Show Gist options
  • Save trhgquan/cc5cce322068f4267cb5a4ddcb34a2b1 to your computer and use it in GitHub Desktop.
Save trhgquan/cc5cce322068f4267cb5a4ddcb34a2b1 to your computer and use it in GitHub Desktop.
For more algorithm, visit https://github.com/trhgquan/CPP
/*
* CDRSANJ - https://www.spoj.com/problems/CDRSANJ/
* Code by @trhgquan - https://github.com/trhgquan
*/
#include <stdio.h>
int f(int x) {
if (x == 0 || x == 1 || x == 2)
return x;
int ret = 0;
while (x % 2 == 0) {
ret += 2;
x /= 2;
}
return ret;
}
int main() {
int x;
scanf("%d", &x);
printf("%d\n", f(x));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment