Redaksiya
This problem says that on the day of planting, the gardener had to use a bucket of water for each of the trees, on the last day - , on the second to last , and so on. The gardener waters the trees with the following amounts of water . Meaning that the gardener must water the trees for days.
We don't know what day the gardener started watering the trees, but we do know that he watered the trees on the last day, and in total used no more than buckets of water. Therefore, we can count how many days the gardener watered the trees moving from the last day.
Knowing the total number of days the gardener planned to water the trees () and the number of days the gardener actually watered the trees, we can find , the number of days the gardener missed.
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0; cin>>n; // Read the number of trees double v = 0; for (int i = n; i >= 1; --i) { v += 1.0 / i; if (v > 0.5) { // Make sure that the total amount of water does not exceed half a bucket break } m++; // Let's count the number of days the gardener watered the trees } cout<<n - m<<"\n"; }