Created
April 9, 2017 14:27
-
-
Save green-coder/2920de69e8c64c6512cb8dc15a5b3d2c to your computer and use it in GitHub Desktop.
Google Code Jam 2017, Qualification Round, compact C solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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