Aperiodic Appointments
문제
Nick has always struggled with maintaining habits. The problem is that he just can't stop maintaining them. If Nick does something times in a row, he has to keep doing it forever.
Luckily, he has started visiting Dr Patternson, an expert in PBT (Pattern Breaking Therapy). The principle of PBT is simple: Nick will visit Dr Patternson every day, and if he has done the same thing times in a row on a specific visit, the doctor will charge him money. This will motivate Nick to not continue this habit.
PBT has worked out great for Nick, as he has now successfully quit all his habits. Except for one, the habit of visiting Dr Patternson. The frequent visits are starting to take a toll on Nick's economy, so your task is to calculate how many times he has to pay the doctor for the next days.
Formally, let be a string consisting of zeroes and ones. A one means that Nick has to pay the doctor on the th day. This string is generated one character at a time, in the following way:
- if .
- If , then if the previous characters contains a pattern that repeats times. More specifically, let . If there is a nonempty string such that the last characters of can be written as , then . Otherwise .
You are given the numbers and , and your task is to calculate the number of ones in the string .
The picture represents Sample 1. An angry face means that Nick had to pay on the corresponding day.
입력
The input consists of one line with the integers and (, ).
출력
Print one integer, the number of ones in the string .
예제
예제 1
7 2
3
예제 2
99 5
19