Logo
(追記) (追記ここまで)

30432번 - Aperiodic Appointments 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB59242047.619%

문제

Nick has always struggled with maintaining habits. The problem is that he just can't stop maintaining them. If Nick does something $K$ 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 $K$ 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 $N$ days.

Formally, let $s = s_1s_2s_3\dots s_N$ be a string consisting of zeroes and ones. A one means that Nick has to pay the doctor on the $i$th day. This string is generated one character at a time, in the following way:

  1. $s_i = 0$ if $i \leq K$.
  2. If $i > K,ドル then $s_i = 1$ if the previous characters contains a pattern that repeats $K$ times. More specifically, let $s' = s_1s_2\dots s_{i-1}$. If there is a nonempty string $t$ such that the last $|t|\cdot K$ characters of $s'$ can be written as $t+t+\dots + t,ドル then $s_i = 1$. Otherwise $s_i = 0$.

You are given the numbers $N$ and $K,ドル and your task is to calculate the number of ones in the string $s$.

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 $N$ and $K$ (1ドル \leq N \leq 10^9,ドル 2ドル \leq K \leq 10^9$).

출력

Print one integer, the number of ones in the string $s$.

제한

예제 입력 1

7 2

예제 출력 1

3

예제 입력 2

99 5

예제 출력 2

19

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2023 A번

  • 문제를 만든 사람: Nils Gustafsson
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /