Official
B - First Contest of the Year 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.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
If the first contest of a year takes place on day \(F\), the contests will be held on days \(F, F + 7, F + 14, \ldots\) in that year.
Notice that day \(x\) of the next year is virtually day \((D + x)\) of this year. Thus, after adding \(7\) to \(F\) repeatedly while \(F\) is less than or equal to \(D\), the resulting \((F - D)\) is the answer. This procedure can be implemented as a while statement.
Sample code
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, f;
cin >> d >> f;
while (f <= d) f += 7;
cout << f - d << '\n';
}
Alternatively, we can avoid using a loop and still find the answer as follows:
Sample code
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, f;
cin >> d >> f;
cout << 7 - ((d - f) % 7) << '\n';
}
posted:
last update: