zoukankan      html  css  js  c++  java
  • Logarithms (数学)

     Logarithms
    Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

    Description

    Download as PDF

    Problem A
    Logarithms 
    Input: 
    Standard Input

    Output: Standard Output

     

    From time immemorial different series has been an integrated part of mathematics. Series is very important for finding values of many important functions such as sin(x), ex, ln(x) etc. The well known formula for finding the value of ln(1-x) is shown below:

    , Here |x|<1.

    However as this formula is true when x is less than 1, a modification is needed to find the formula for any integer. For any integer n the following relationship is true:

    ,

                      Here |x|<1 and it is a real number, n is a positive integer and L is a non-negative integer.

    But for a given integer n, L can have more than one value. Your job is to find the smallest possible value of L and for that L find the value of x.

    Input

    The input file contains around 10000 line of input. Each line contains a single integer n (0<n<231-1). Input is terminated by a line containing a zero.

    Output

    For each line of input produce one line of output. This line contains one integer followed by one floating point number. The integer number denotes the smallest possible value of L and floating-point number denotes the corresponding value of x. This floating-point number should have eight digits after the decimal point.

    Sample Input                              Output for Sample Input

    6

    7

    300

    0

    2 0.18798830

    2 0.05265302

    6 0.25637435


    Problemsetter: Shahriar Manzoor

    Special Thanks: Arifuzzaman Arif, Sohel Hafiz, Derek Kisman

     由题中两个formula可以得到:

    ln(n) - ln(1 - x) = L.注意到fabs(x) < 1,得到0 < ln(1 - x) < ln2,所以ln(n) - ln2 < L,于是L取[ln(n) - ln2  + 1]即可([x]代表取小于x的最大整数)

    AC CODE

     1 //Memory: 0 KB        Time: 24 MS
     2 //Language: ANSI C 4.1.2        Result: Accepted
     3 
     4 #include <stdio.h>
     5 #include <math.h>
     6 
     7 int main()
     8 {
     9     int n, L;
    10     double x;
    11     const double u = log(2);
    12     while(scanf("%d", &n) && n)
    13     {
    14        double m = log(n);
    15        L = ceil(m - u);
    16        x = 1- exp(m - L);
    17        printf("%d %.8lf\n", L, x);
    18     }
    19     return 0;
    20 }



  • 相关阅读:
    51nod 1163 最高的奖励
    51nod 1191 消灭兔子
    51nod 2538 二三排列
    node做渲染服务器的实现
    gulp静态服务器的搭建
    canvas中裁切(橡皮檫)的应用--探照灯,点击去除遮罩
    canvas中图片、视频的加载(截图、切片)
    canvas中笔触基础知识
    Gitee的使用流程
    gulp的使用
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910486.html
Copyright © 2011-2022 走看看