Uva--107 (数学,精度处理)
2014-06-08 11:53:50
题意&思路:题目很绕。。。。简单的说就是给出(N+1)^k , N^k 让你求:1+N+N^2+....+N^(K-1)(转化为:(N^k - 1) / (N -1 ))和(N+1)^k - N^k 。不多说,直接从N枚举,公式搞之。
#include <cstdio> #include <cmath> #include <iostream> using namespace std; const double eps = 1e-10; int main(){ double h,w; while(scanf("%lf %lf",&h,&w) == 2){ if(h == 0 && w == 0) break; double n = 1; while(fabs(log(h) / log(w) - log(n + 1) / log(n)) >= eps) ++n; double k = log(h) / log(n + 1); if((int)n == 1) printf("%.0lf %.0lf\n",k,h * (n + 1) - w * n); else printf("%.0lf %.0lf\n",(w - 1) / (n - 1),h * (n + 1) - w * n); //printf("n : %.0lf, k : %.0lf\n",n,k); } return 0; }