Official
A - Full Moon 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.
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: