Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
是个水题,二分一下就可以了掉了一个continue导致X-Y==1時输出两次答案嚷昂一次也是醉了 还有坑爹的C标准,log(int)再次CE。。。跪了 #include <iostream> #include <stdio.h> #include <cmath> using namespace std; int main() { while(1){ long long int X, Y; scanf("%I64d%I64d", &X, &Y); if(X==0 && Y==0) return 0; if(X==1){ cout << "0 1\n"; continue; } else if(Y==1){ long long int N = 1; long long int K = (long long int)(log(X+0.0)/log(2.0)+1e-11); printf("%I64d %I64d\n", K, 2*X-1); continue; } else if(X-Y==1){ long long int K = 1; long long int N = Y; printf("1 %I64d\n", 2*N+1); continue; } long long int minK = 1; while(pow(X+0.0, 1.0/minK)-pow(Y+0.0, 1.0/minK) > 1){ minK *= 2; } long long int low = minK/2, up = minK, ans = -1; while(low < up){ long long int mid = (low + up)/2; double t = pow(X+0.0, 1.0/mid)-pow(Y+0.0, 1.0/mid); if(abs(t-1.0) < 1e-10){ ans = mid; break; } if(t > 1.0){ low = mid+1; } else{ up = mid-1; } } if(ans == -1) ans = up; long long int K = ans; long long int N = (long long int)(pow(Y+0.0, 1.0/K)+1e-10); long long int ans1 = 0, ans2 = 0; long long int p = 1; for(long long int k = 0; k < K; k++){ ans1 += p; p *= N; } ans2 += p; for(long long int k = 0; k < K; k++){ p /= N; p *= (N+1); ans2 += p; } printf("%I64d %I64d\n", ans1, ans2); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator