Skip to content

Instantly share code, notes, and snippets.

@green-coder
Created April 9, 2017 14:27
Show Gist options
  • Save green-coder/2920de69e8c64c6512cb8dc15a5b3d2c to your computer and use it in GitHub Desktop.
Save green-coder/2920de69e8c64c6512cb8dc15a5b3d2c to your computer and use it in GitHub Desktop.
Google Code Jam 2017, Qualification Round, compact C solution
/**
* Complexity O(log(k))
*/
private static String solve2(long n, long k) {
while (k != 1) {
n = ((n & 1) == 0 && (k & 1) == 1) ? (n / 2) - 1 : n / 2;
k = k / 2;
}
long bigHalf = n / 2;
long smallHalf = (n - 1) - bigHalf;
return "" + bigHalf + " " + smallHalf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment