Created
February 9, 2014 09:50
-
-
Save KT-Yeh/8896844 to your computer and use it in GitHub Desktop.
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 <cstdio> | |
#include <cmath> | |
using namespace std; | |
typedef long long int llt; | |
int main() | |
{ | |
// freopen ("input.txt","rt",stdin); | |
int H,W; | |
while (scanf("%d%d",&H,&W) != EOF){ | |
if (!H && !W) break; | |
// klog(N+1) = logH | |
// klogN = logW | |
// 第一式除以第二式 | |
double C = log(H) / log(W); | |
int L = 1, R = 2147483645, mid = (L + R)/2; | |
while (L != R){ | |
if (log(mid+1) / log(mid) - C > 0.000000000001) L = mid+1; | |
else if (log(mid+1) / log(mid) - C < -0.000000000001) R = mid; | |
else break; | |
mid = (L + R) / 2; | |
} | |
int N = mid; | |
int k = round (log(H) / log(N+1)); | |
// 不要用logW/logN避免N=1的情況,使用round四捨五入 | |
// N和k已經有了,剩下只是統計數量和高度 | |
llt notWorking = 0; | |
llt totalHeight = 0; | |
W = 1; | |
for (int i = 0; i < k; i++){ | |
notWorking += W; | |
totalHeight += (H * W); | |
W *= N; | |
H /= (N+1); | |
} | |
printf("%lld %lld\n",notWorking, totalHeight+(H * W)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment