포럼
문제 ICPC00293

A. Aperiodic Appointments

설명

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:
- \(s_i = 0\) if \(i \leq K\).
- 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
출력
3
예제 2
입력
99 5
출력
19
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2023

평가 및 의견

A. Aperiodic Appointments

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

A. Aperiodic Appointments

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8