Official
A - Full Moon Editorial
by
A - Full Moon Editorial
by
nok0
初心者の方へ
- プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは practice contest の問題A「Welcome to AtCoder」をお試しください。言語ごとに解答例が掲載されています。
- また、プログラミングコンテストの問題に慣れていない方は、 AtCoder Beginners Selection の問題をいくつか試すことをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
この問題は while 文、 for 文のような繰り返し文をうまく使えるかを聞いています。while 文、for 文に関する情報を知りたい人は APG4b の記事 などを参考にしてみてください。
この問題では、\(M\) 日目、\(M+P\) 日目、\(\ldots\) の順にその日が \(N\) 日目までかを確認し、\(N\) 日目までであれば答えに \(1\) を加算する、そうでなければ処理を打ち切ることで答えを求められます。これは while 文によって実装できます。以下に C++ と Python での実装例を示します。
- 実装例(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;
}
- 実装例(Python)
n, m, p = map(int, input().split())
res = 0
while m <= n:
res += 1
m += p
print(res)
posted:
last update: