Integer28. The days of the week are numbered as follows: 1 - Monday, 2 - Tuesday, ..., 6 - Saturday, 7 - Sunday. Given an integer K lying in the range 1-365, and an integer N lying in the range 1-7. Determine the number of the day of the week for the K-th day of the year, if it is known that this year January 1 was the day of the week with the number N.

Solution in Python 3:

import random

week_days = {
1: 'Monday',
2: 'Tuesday',
3: 'Wednesday',
4: 'Thursday',
5: 'Friday',
6: 'Saturday',
7: 'Sunday'
}

K = random.randrange(1,366)
N = random.randrange(1,8)
print("K = ",K,"; N = ",N)
#K = 29

i = (1+N-1)%7 + 1
print("January, 1: ", 1)
print("Number of the day of the week: ", i)
print("Day of the week:",week_days[i])

i = (K+N-1)%7 + 1
print()
print("Number of the day of the year: ", K)
print("Number of the day of the week: ", i)
print("Day of the week:",week_days[i])