Official
A - Exponential Plant Editorial by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
Use a while
statement to repeatedly add the delta to the height of the plant until it exceeds Takahashi’s height. This simulation will allow you to solve this problem.
Also, the height at day \(30\) is \(1073741823\, \mathrm{cm}(> 10^{9}\, \mathrm{cm})\), so just using a while statement to find the daily height is fast enough.
Sample code (C++):
#include <bits/stdc++.h>
using namespace std;
int main(){
int h;
cin >> h;
int ans = 0;
int now = 0;
while (now <= h) {
now += 1 << ans;
ans++;
}
cout << ans << endl;
}
Sample code (Python):
h=int(input())
now=0
ans=0
while now<=h:
now+=1<<ans
ans+=1
print(ans)
posted:
last update: