公式
A - 小雨の予報 / Light Rain Forecast 解説 by admin 印刷ページ
swe-2-highEditorial
Day 1 is \(A\) millimeters and each subsequent day adds \(B\), so the amounts form an arithmetic sequence with first term \(A\) and common difference \(B\). The amount on day \(i\) (\(i = 1, 2, \ldots, N\)) is
\[A + B \times (i - 1).\]
The program simply loops i from \(0\) to \(N - 1\) and prints a + b * i.
Since \(A, B\) can be up to \(10^9\) and \(N \leq 100\), values can reach about \(10^{11}\), which overflows a 32-bit integer. Using long long is essential.
Complexity
Time complexity is \(O(N)\) and space complexity is \(O(1)\) (excluding the output itself).
投稿日時:
最終更新: