Last active
October 28, 2019 16:15
-
-
Save WindAzure/5fb62acadda05b4fe7c8d6a00ee6436c to your computer and use it in GitHub Desktop.
UVa 1591
This file contains hidden or 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
#include <limits> | |
#include <stdio.h> | |
int main() | |
{ | |
auto N = 0, Sp = 0, Sq = 0; | |
while (~scanf("%d%d%d", &N, &Sp, &Sq)) | |
{ | |
auto baseLengthOfP = static_cast<long long>(Sp) * (N - 1); | |
auto baseLengthOfQ = static_cast<long long>(Sq) * (N - 1); | |
auto A = 0, B = 0; | |
auto K = std::numeric_limits<long long>::max(); | |
for (auto currentA = 0; currentA <= 31; currentA++) | |
{ | |
auto QofsBase = baseLengthOfP + (baseLengthOfP << currentA); | |
for (auto currentB = 0; currentB <= 31; currentB++) | |
{ | |
auto Qofs = QofsBase >> currentB; | |
if (Qofs >= baseLengthOfQ && Qofs < K) | |
{ | |
K = Qofs; | |
A = currentA; | |
B = currentB; | |
} | |
} | |
} | |
printf("%lld %d %d\n", K + Sq, A, B); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment