Official

A - Full Moon Editorial by en_translator


For beginners

This problem asks for a proper use of loops like while statements and for statements. For more details on while and for statements, see for example the article in APG4b (in Japanese).

The answer for this problem can be found by inspecting each of day \(M\), day \(M+P\), \(\ldots\) to check whether it is within the first \(N\) days, and add \(1\) to the answer if it is, and terminating the loop if it is not. This can be implemented with a for statement. The following it sample codes in C++ and Python.

  • Sample code (C++)
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    int res = 0;
    while(m <= n) {
        res++;
        m += p;
    }
    cout << res << endl;
}
  • Sample code (Python)
n, m, p = map(int, input().split())
res = 0
while m <= n:
    res += 1
    m += p
print(res)

posted:
last update: