公式

A - Exponential Plant 解説 by en_translator


For beginners

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)

投稿日時:
最終更新: