Hello Guys, The editorials for January Cook of are cooked (first two only).

### Problem: SURVIVE

#### Problem Statement:

Given a shop opening from Monday to Saturday, you are allowed to buy N sweets everyday the shop is open and you eat K sweets everyday, determine if you can survive for next S days.

#### Difficulty:Cakewalk

#### Solution:

The constraints of problem are small enough to check for everyday.

For every ith day (1<=i<=S) not being divisible by 7, buy N sweets. Eat K sweets everyday. If at any day you have less than K sweets to eat, answer is impossible.

If you survive S days, and supposing C is the number of remaining sweets and A being number of days you bought sweets, just subtract C/N from A. (The number of sweet boxes untouched).

Link to Solution here.

### Problem: MULTHREE

#### Problem Statement:

Given K, d0 (first digit) and d1 (second digit), we care to check that K-digit number is divisible by 3. if K> 2, Remaining digits of our Number are given by:

\begin{equation}

D_{i} = {\textstyle \sum^{j-1}*{0}} D*{j} (mod 10)

\end{equation}

#### Difficulty: Easy

#### Solution:

First thing to note is that if sum of digits of a number is divisible by 3, number if divisible by 3.

Another thing, (I would recommend running a brute force for all possible values of d0 and d1 to observe this pattern, do give a try before reading).

After first three digits, only the pattern “2486” repeats till end of the number. This means that we can split our number into 4 parts.

- First 3 digits,
**manually take sum.** - Next 0 to 3 digits (pattern may start at 4, 8 or 6, Taking care of that).
- “2486” X number of times. ** Add X*20 to sum**.
- Last 0 to 3 digits (pattern may end at 2, 4 or 8).

**Finding X**: Check for start point of pattern (will be from p = 3 to 6 in 0-based indexing), X = floor((K-p)/4).

**Edge case**: If fourth digit is 0, we take sum of first three digits and check its divisibility by 3.

Link to Solution here.

PS: I have intentionally kept the length of editorials short. If you don’t get it, feel free to post a comment.