Nine problems from AtCoder, one of the two biggest competitive programming judges. They are submitted on AtCoder itself, and they follow this week's order: loops and accumulators first (a FizzBuzz sum, a bank balance that grows by 1%, points within a distance, drinks until someone is drunk), then digits (the larger digit sum, a number divisible by its digit sum, the next number with equal digits, a number that keeps changing, numbers written in another base).
The statements are in English (and Japanese). Every one of them needs only one
loop — and several need long long.
- FizzBuzz Sum: add up the numbers from 1 to
Nthat are divisible by neither 3 nor 5. WithNup to 10⁶ the sum passes 2 · 10⁹:long long. - 1%: add
balance / 100each year — integer division does the "fractions of a yen are discarded" — and count the years with awhile. - Distance: compare
x * x + y * ywithD * Dinlong long, with no square root at all, so no rounding can go wrong. - Alcoholic: keep the alcohol as
V · P(in hundredths of a millilitre) so everything stays an integer, and stop at the first drink that goes pastX · 100. - Large Digits and Digit Sums: the digit-sum loop from the lesson. In
Digit Sums, peel the digits off a copy —
Nis needed for the division at the end. - AtCoder Beginner Contest 111: try 111, 222, …, 999 in order and stop at the
first one that is at least
N. - 200th ABC-200: do exactly what it says,
Ktimes. Appending200toNisN * 1000 + 200, which needslong long. - Base K: the digits of
Aare written as an ordinary number. Peel them off with% 10, and multiply each by its place value — 1,K,K², … — kept in a variable that is multiplied byKevery round.