generate functionTue, 14 Feb 2023

Vasya has n pairs of socks. Every morning, when going to school, Vasya has to put on a pair of socks. In the evening, after coming home from school, Vasya takes off his socks and throws them away. Every m-th day (on days with numbers m, 2m, 3m, ...) Mom buys Vasya one pair of socks. She does it late at night, so Vasya can put on new socks not until the next day. How many consecutive days will Vasya have enough socks for? Input data The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100) separated by a space. Output Print a single integer — the answer to the problem.

def sock_pairs(n, m): total_days = 0 all_socks = n # loop till there are socks print("Here are all the socks: ", all_socks) while all_socks > 0: all_socks = all_socks - 1 print("I took 1 sock, so now I have: ", all_socks) total_days = total_days + 1 if total_days % m == 0: all_socks = all_socks + 1 print("It's ", total_days, " days, so I have a new sock, so now I have: ", all_socks) print("total days", total_days) return total_days sock_pairs(5, 2)

Questions about programming?Chat with your personal AI assistant