Problem B. S06-07 工业产值(翻一番问题log函数简单秒解方法)
假设今年的工业产值为100万元,产值增长率从键盘输入,请编程计算工业产值过多少年后可实现翻一番(即增加1倍)。
输入
一个大于0的实数
输出
假如输入的数为1,则: When grow rate is 100%, the output can be doubled after 1 years.
样例
标准输入复制文本 |
0.01 |
标准输出复制文本 |
When grow rate is 1%, the output can be doubled after 70 years. |
标准输入复制文本 |
0.3 |
标准输出复制文本 |
When grow rate is 30%, the output can be doubled after 3 years. |
标准输入复制文本 |
2.5 |
标准输出复制文本 |
When grow rate is 250%, the output can be doubled after 1 years. |
前提必备知识:1、log函数的应用
2、ceil向上取整
#include <bits/stdc++.h>
using namespace std;
int main()
{ double rate;
cin>>rate;
double a=log(2.0)/log(1+rate);
cout<<"When grow rate is "<<rate*100<<"%, the output can be doubled after"<<" "<<ceil(a)<<" "<<"years.";
return 0;
}