Problem:


Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
l = map(int, input().split())
c = b - 1
if a > b:
    d = 1
    while a > b:
        b += c
        d += 1
    print(d)
else:
    print(1)

Submission status: Accepted

Solution code:
N, k = map(int, input().split())
num = input().rstrip().split()

t = 0

for i in range(N):
  if num[i] == "1":
    one = i
    break
    
N -= 1


while(N > 0):
  N -= (k-1)
  t += 1



print(t)

Submission status: Accepted

Solution code:
str_n, str_k = input().split()
n = int(str_n)
k = int(str_k)
str_a = input().split()
a = [int(str) for str in str_a]

for i, num in enumerate(a):
    if num == 1:
        fir = i

left = fir
right = n - fir - 1

if k == 2:
    print(n - 1)
elif n == k:
    print(1)
else:
    print((n+k-3)//(k-1))

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
print(math.ceil((n-1) / (k-1)))

Submission status: Accepted

Solution code:
import math
N,K = [int(x) for x in input().split(" ")]
A =  [int(x) for x in input().split(" ")]
ans = math.ceil((N -1)/(K -1))
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == k:
    ans = 1
elif (n-k) % (k-1) == 0:
    ans = 1 + (n-k) // (k-1)
else:
    ans = 2 + (n-k) // (k-1)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
listA=list(map(int,input().split()))
N=listA[0]
K=listA[1]
A=list(map(int,input().split()))
Anp=np.array(A)
if(N/K==1):
    print(1)
elif((N-1)%(K-1)==0):
    print(int((N-1)/(K-1)))
else:
    print(int((N-1)/(K-1))+1)

Submission status: Accepted

Solution code:
import math
N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

if N == K:
    ans = 1
else:
    ans = 1 + math.ceil((N-K)/(K-1))

print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    NK = input().rstrip().split(' ')
    N = int(NK[0])
    K = int(NK[1])
    line = input().rstrip().split(' ')
    A = list(map(lambda x: int(x), line))
    
    # 1 の位置から左右の端までK個づづ変更すればよい
    # one = A.index(1)
    if N == K:
        print("1")
        exit()
    right = 0
    left = N -1
    count = 0
    while True:
        right += (K-1)
        count += 1
        if right >= left:
            print(count)
            break
        left -= (K-1)
        count += 1
        if right >= left:
            print(count)
            break

Submission status: Accepted

Solution code:
import math
import sys
n, c = map(int, input().split())
if(n==c):
    print(1)
    sys.exit()
num = list(map(int, input().split()))
for i in range(len(num)):
    if num[i] == 1:
        first = i
        break
rightCount = math.ceil((n - first - 1) / (c - 1))
if((n - first - 1) % (c - 1) == 0):
    b = 0
else:
    b = c - 1 - ((n - first - 1) % (c - 1))

leftCount = math.ceil((first - b) / (c - 1))
print(leftCount + rightCount)

Submission status: Accepted

Solution code:
[N,K] = [int(i) for i in input().split()]

num = (N-K)//(K-1) + 1

if (N-K)%(K-1)==0:
  print(num)
else:
  print(num+1)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
import math
print(math.ceil((N-1)/(K-1)))

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
import math

n, k = map(int, input().split())

if n == k:
    print(1)
else:
    print(math.ceil((n - 1) / (k - 1)))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

min_index = 0
for index, i in enumerate(A):
    if i == 1:
        min_index = index
        break

if min_index == 0:
    left = 0
else:
    left = int((min_index + K - 2) / (K - 1))
    if min_index % (K - 1):
        add = (K - 1) - int(min_index % (K - 1))
        min_index += add
if min_index >= N - 1:
    right = 0
else:
    right = int((N - min_index + K - 3) / (K - 1))
ans = left + right

print(ans)

Submission status: Accepted

Solution code:
l = input().split()

N = int(l[0])
K = int(l[1])

if N == K:
    print(1)
    
else:
    print( 2 + (N - K) // (K - 1) - int((N-K)%(K-1)==0) )

Submission status: Accepted

Solution code:
N,K =[int(i) for i in input().split(' ')]

A = [int(i) for i in input().split(' ')]
"""
index_1 = -1

for i in range(len(A)):
    #print(index_1)
    if A[i]==1:
        index_1 = i
        break

ans = 0
if index_1%(K-1)==0:
    ans += index_1 // (K-1)
else:
    ans += index_1 //(K-1) + 1

if (N-index_1 -1)%(K-1)==0:
    ans += (N - index_1-1) // (K-1)
else:
    ans += (N - index_1 -1) //(K-1) + 1
    
print(ans)
"""
ans =0
if (N-1)%(K-1) ==0:
    ans = (N-1)//(K-1)
else:
    ans = (N-1)//(K-1) +1
print(ans)

Submission status: Accepted

Solution code:
import sys


def func(N, K):
    if K == N:
        return 1
    elif K - 1 == 1:                                                                                                                                  
        return N - 1
    else:
        r = N // (K - 1)                                                                                                                              
        m = N % (K - 1)
        if m == 0 or m == 1:
            return r
        return r + 1

if __name__ == '__main__':
    N, K = map(int, sys.stdin.readline().split())
    A = map(int, sys.stdin.readline().split())
    print(func(N, K))

Submission status: Accepted

Solution code:
st = str(input())
tmp = st.split(" ")
N = int(tmp[0])
K = int(tmp[1])
y = str(input())
if N <= K:
    print(1)
else:
    x = 0
    if (N - K) % (K - 1) != 0:
        x = 1
    print(((N - K) // (K - 1) + x + 1))

Submission status: Accepted

Solution code:
N,K=list(map(int, input().split()))
A=list(map(int, input().split()))

answer=0
if N==K:
    print(1)
elif K!=2:
    if A.index(1)==0 or A.index(1)==N-1:
        if N-K>K:
            if (N-K)%(K-1) == 0:
                answer=int(1+((N-K)/(K-1)))
            else:
                answer=int(((N-K)/(K-1))+2)
        else:
            answer=2
        print(answer)
    else:
        left_items=A.index(1)
        right_items=(N-1)-A.index(1)
        if left_items<K or right_items<K:
            if (N-K)%(K-1) == 0:
                answer=int(1+((N-K)/(K-1)))
            else:
                answer=int(((N-K)/(K-1))+2)
            print(answer)

        left=left_items%(K-1)
        right=right_items%(K-1)
        if left+right+1 == K:
            answer=1+(int(left_items/(K-1))+int(right_items/(K-1)))
            print(answer)
        else:
            answer=1+(int(left_items/(K-1))+int(right_items/(K-1)))+1
elif K==2:
    answer=N-1
    print(answer)

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
l=list(map(int,input().split()))
count=0
num=1000000
mi=min(l[0:k])
if(mi<num):
    num=mi
for i in range(0,len(l),k-1):
    count+=1
    if(i<len(l)-1 and i+k-1>=len(l)):
        count+=1
        break
print(count-1)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))

i_1 = a.index(1)

ans = 9999999999

left = len(a[:i_1])
right = len(a[i_1:])

for i in range(k):
    x = left  - i
    y = right - (k-i)
    
    if x < 0 or y < 0:
        continue
    
    count = 1 + math.ceil(x/(k - 1)) + math.ceil(y/(k - 1))
    ans = min(ans,count)

print(ans)

Submission status: Accepted

Solution code:
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,k = Is()
ls = Is()
_1 = ls.index(1)
ans = []
for i in range(_1-k+1,_1+k):
    ans.append(math.ceil(i/(k-1))+math.ceil((n-1-i)/(k-1)))
print(min(ans))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
l = input().split()
 
cnt=0
end_point=0 
for i,e in enumerate(l):
    if i !=end_point:
        continue 
    #print(i)
    #print(e)
    #print(l)
    #print(l[i:i+K])
    m= min(l[i:i+K])
    try:
        cnt =cnt+1
        for j in range(K):
            l[i+j]=m
        if i+j == len(l)-1:
            cnt=cnt-1
    except:
        print(cnt)
    end_point=i+j
#print(cnt)
#if i==len(l)-1:
    #print(cnt)

Submission status: Accepted

Solution code:
N,K=map(int,input().split(' '))
print( (N-1+K-2) // (K-1))

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())

a = []
a.append(map(int, raw_input().split()))

keylist = range(N)
colum = M
valuelist = a

A = {k: v for k, v in zip(keylist, valuelist)}


minkey = min(A, key = A.get)
minnum = min(A.values())

sum1 = 0

if minkey%(colum-1) != 0:
    sum1 = sum1 + (minkey//(colum-1))+1 
    
    
else:
    sum1 = sum1 + minkey//(colum-1)

num1 = N - minkey

if (num1-1)%(colum-1) != 0:
    sum1 = sum1 + ((num1-1)//(colum-1))+1
else: 
     sum1 = sum1 + (num1-1)//(colum-1)


print sum1

Submission status: Accepted

Solution code:
import math, sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]


n, k = LI()
a = LI()

result = math.ceil((n - k) / (k - 1)) + 1

print(result)

Submission status: Accepted

Solution code:
import math
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
for i in range(len(a)):
    if a[i]==1:
        p1=i

print(math.ceil((n-k)/(k-1))+1)

Submission status: Accepted

Solution code:
import math

n,k = map(int, input().split())

print(math.ceil((n-1)/(k-1)))

Submission status: Accepted

Solution code:
str = input()
n, k = str.split(' ')
ni = int(n)
ki = int(k)
str = input()

if ni == ki:
    print(1)
elif ki == 2:
    print(ni-1)
elif ((ni-1)%(ki-1) == 0):
    print(int((ni-1)/(ki-1)))
else:
    print(int((ni-1)/(ki-1))+1)

Submission status: Accepted

Solution code:
N,K=(int(i) for i in input().split())
A = list(int(i) for i in input().split())  
minNum=0
i=0
A2=[]
ans=0

while i<N:    
   
    if i==0:
        i=i+K
    else:
        i=i+K-1

    ans+=1
    
print(ans)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
x = A.index(1)
y = x + 1
c = 0
a = (math.ceil((y-1)/(K-1))) * (K-1) + 1
c += math.ceil((y-1)/(K-1))
c += math.ceil((N-a)/(K-1))
print(c)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
lis = list(map(int,input().split()))
print(int(math.ceil((n-1)/(k-1))))

Submission status: Accepted

Solution code:
import sys

N, K = map(int, input().split())
A_list = list(map(int, input().split()))

for k in range(N):
    if(A_list[k] == 1):
        k1 = k + 1
        break

ans = sys.maxsize

for k in range(k1 - K + 1, k1 + 1):
    # print(k1, k)
    if(k < 1):
        continue
    tmp_ans = 1
    tmp_ans += (k - 1) // (K - 1)
    if((k - 1) % (K - 1) != 0):
        tmp_ans += 1

    if(k + K <= N):
        tmp = N - k - K + 1
        tmp_ans += tmp // (K - 1)
        if(tmp % (K - 1) != 0):
            tmp_ans += 1

    # print(tmp_ans)
    if(ans > tmp_ans):
        ans = tmp_ans

print(ans)

Submission status: Accepted

Solution code:
N,K=[int(i) for i in input().split()]
A=[i for i in input().split()]
if N==K:
    print(N//K)
for i in range(100000):
    if K+1+(K-1)*i<=N and N<=K+(K-1)+(K-1)*i:
        print(i+2)
        break

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))



if N==K:
    print(1)
elif K==2:
    print(N-1)
elif K==3:
    tmp = N//(K-1)
    if N%(K-1) == 2:
        print(tmp+1)
    else:
        print(tmp)
else:
    tmp = N//(K-1)
    print(tmp + (1 if N%(K-1) != 0 else 0))

Submission status: Accepted

Solution code:
#coding: utf-8
import math

def up(n):
    print(n % 1)

if __name__ == "__main__":
    n,k = map(int,input().split())
    a = input().split(" ")
    prev = True
    pre,post = (0,0)
    remain = k
    result = 0
    for i in range(n):
        a[i] = int(a[i])
        if a[i] != 1 and prev == True:
            pre += 1
        if a[i] == 1:
            prev = False
            result += int(pre / (k-1)) + 1
            remain = k - (pre % (k-1) + 1)
            continue
        if prev == False and remain > 0:
            a[i] = 1
            remain -= 1
            continue
        if a[i] != 1 and prev == False:
            post += 1

    result += math.ceil(post / (k-1))

    print(result)

Submission status: Accepted

Solution code:
import math
def main15():
    strbuf1 = input('');
    strbuf2 = input('');
    strbufs1 = strbuf1.split();
    strbufs2 = strbuf2.split();
    buf1 = [];
    buf2 = [];
    ba = 0;
    for i in range(2):
        buf1.append(int(strbufs1[i]));
    for i in range(buf1[0]):
        buf2.append(int(strbufs2[i]));
        if(buf2[i] == 1):
            ba = i;
            break;
    are = buf1[1] - 1;
    kai1 = math.ceil(ba/are);
    kk = are * kai1 - ba;
    kai2 = math.ceil((buf1[0] -(ba+1+kk))/are)
    print(int(kai1+kai2));

def main16():
    strbuf = input('');
    num = int(strbuf);
    kazu = 0;
    number = 1;
    while(kazu<num):


        kazu = kazu + 1;

        number = number + 1;


if __name__ == '__main__':
    main15()

Submission status: Accepted

Solution code:
from math import ceil

N, K = map(int, input().split())
A = list(map(int, input().split()))

count = 0
N -= K
count += 1

count += ceil(N/(K-1))
print(count)

Submission status: Accepted

Solution code:
# -1- method

def A(n,k,array,i):
	count = n
	if k >= n:
		count = 1
	elif i == n-1:
		count = int(-(-(n-1)/k-1)) 
	else:
		count = -(-(n-1)//(k-1))
	return count

	
	
baseinfo = input().split(" ")
baseinfo = [int(c) for c in baseinfo]
n, k = baseinfo[0], baseinfo[1]

array = input().split(" ")
array = [int(c) for c in array]

#print(n,k,array.index(1))
print(A(n, k, array, array.index(1)))

Submission status: Accepted

Solution code:
# https://beta.atcoder.jp/contests/abc101/tasks/arc099_a
# C - Minimization

# C_Minimization.py

N, K = map(int, input().strip().split(" "))
A = list(map(int, input().strip().split(" ")))

for i in range(N):
    if A[i] == 1:
        min_index = i

left = min_index + 1
count = 0
while left > 1:
    left -= K-1
    count += 1
if left == 1:
    left = 0
else:
    left -= 1

right_start = N - (min_index + 1) + left + 1
while right_start > 1:
    right_start -= K-1
    count += 1

print(count)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    mindex = a.index(1)

    min_t = 10000000
    for i in range(mindex-k+1, mindex+1):
        if i >= 0:
            t = 1 + (i+k-2) // (k-1) + (len(a)-(i+k-1)-1+k-2) // (k-1)
            min_t = min(t, min_t)

    print(min_t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]


ans = (n-1)//(k-1) + min((n-1)%(k-1),1)
print(ans)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().strip().split(" ")))
A = list(map(int, input().strip().split(" ")))
min_index = A.index(min(A))
action = 0

q, mod = divmod(min_index, K-1)
m = q
if((mod != 0) or (mod == 0 and q == 0)):
    m += 1
action += m 
res_list_length = N - (K + (m - 1)*(K - 1)) 
if(res_list_length != 0):
    res_list_length += 1
q, mod = divmod(res_list_length - 1, K-1)
m = q
if((mod != 0)  or (mod == 0 and q == 0)):
    m += 1
action += m 
print(action)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

rem = N - K
if rem%(K-1) == 0:
    print(1 + rem//(K-1))
else:
    print(2 + rem//(K-1))

Submission status: Accepted

Solution code:
#coding:utf-8

n, k = input().split()
A_raw = input().split()

A = sorted(A_raw) 
N = int(n)
K = int(k)

lef = N - K 

if lef%(K-1) > 0:
    ans = lef // (K-1) + 2

elif lef%(K-1) == 0:
    ans = lef // (K-1) + 1

print(ans)

Submission status: Accepted

Solution code:
nk = input().split(" ")
n = int(nk[0])
k = int(nk[1])
a = input()
s = -(-(n-1) // (k-1))
print(s)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

A = list(map(int,input().split()))

X = A.index(1) #Xは1のindex

if X<K or N-K<=X:
    ans = 1+((N-K)//(K-1))
    if (N-K)%(K-1)>0: ans += 1
    print(ans)
else:
    min_ans = N
    for i in range(K):
        LR = [X-K+i+1,N-X-1-i]
        #print(LR)
        ans = 1
        for a in LR:
            ans += a//(K-1)
            if a%(K-1)>0: ans += 1
        if ans < min_ans: min_ans = ans
    print(min_ans)

Submission status: Accepted

Solution code:
#encoding: utf-8

n,k=map(int,input().split())

a=[int(i) for i in input().split()]

for i in range(len(a)):
    if a[i]==1:
        num=i
count=0
num0=num
num1=num
#up
while(1):
    num+=(k-1)
    count+=1
    if num>=n:
        num0-=num-n
        break

while(1):
    if num0<=1:
        break
    num0-=(k-1)
    count+=1
count2=0
num01=num1
while(1):
    num01-=(k-1)
    count2+=1
    if num01<=1:
        num1+=1-num01
        break
while(1):
    if num1>=n:
        break
    num1+=(k-1)
    count2+=1
print(min(count,count2))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
num = list(sorted(map(int,input().split())))
cnt = 0
while num[0]!=num[-1]:
  for i in range(1,K):
    if cnt<1:
      num[i]=num[i-1]
    else:  
      j = (K-1)*cnt
      if i + j>=num[-1]:
        break
      num[i+j]=num[j]
      
  cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
s = 0

a = [0]
a = input().split()

b = a.index('1')

s = -( -(n-1) // (k-1) )

print(s)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a_list = map(int, input().split())

ans = 0

while True:
    if n > k:
        ans += 1
        n -= (k-1)
    else:
        ans += 1
        break

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = [int(x) for x in input().strip().split()]
    line = [int(x) for x in input().strip().split()]
    counter = K - 1
    result = 0
    while counter < N:
        counter += K - 1
        result += 1
    if counter - (K - 1) < N - 1:
        result += 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
x = 0
while N > 0:
    if x == 0:
        N = N - K
        x += 1
    else:
        N = N - (K-1)
        x += 1
print(x)

Submission status: Accepted

Solution code:
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

if N == K:
    print(1)
    exit()

if K == 2:
    print(N - 1)
    exit()

if N % K != 0:
    print((N - 1) // (K - 1) + 1)
else:
    print((N - 1) // (K - 1))

Submission status: Accepted

Solution code:
import math

N,K=map(int,input().split())
A=list(map(int,input().split()))

x=A.index(1)

#1の左側を埋める

B=math.ceil(x/(K-1))


#Bで何個目まで塗られたか.

if B==0:
    y=1
else:
    y=(B-1)*(K-1)+K

#右側を埋める.

C=math.ceil((N-y)/(K-1))

#print(B,y,C)

print(B+C)

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
if N == K:
  print 1
elif (N-1) % (K-1) == 0:
  print (N-1) / (K-1)
else:
  print (N-1) / (K-1) + 1

Submission status: Accepted

Solution code:
q="C"
if q=="A":
	S=input()
	print(sum((i=="+")-(i=="-")for i in S))
if q=="B":
	a=int(input())
	b=sum(int(i) for i in str(a))
	print("Yes" if a%b==0 else "No")
if q=="C":
	N,K=map(int,input().split())
	A=[int(i) for i in input().split()]
	func=lambda a,b:int(a/b) if a%b==0 else int(a/b+1)
	print(1+func((len(A)-K),K-1))
if q=="D":
	K=int(input())
	S=lambda x:sum(int(i) for i in str(x))
	#for i in range(1,110):
	r=0
	for i in range(1,10**15):
		a=i
		b=int(K/10)*10+9
		if a/S(a)<=b/S(b):
			print(a)
			r+=1
			if r==K:
				break

Submission status: Accepted

Solution code:
N,K = map(int,input().split(' '))
A = [int(i) for i in input().split(' ')]

if K == 2:
    print(N-1)
elif N % (K-1) > 1:
    print(N // (K-1) + 1)
else:
    print(N // (K-1))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
counter = 0

A = input().split()
while (1+counter*(K-1)<N):
  
  





  counter +=1

print(counter)

Submission status: Accepted

Solution code:
#/usr/bin/env python3

import math

if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    print(max(1, math.ceil((len(A) - K) / (K-1)) + 1))

Submission status: Accepted

Solution code:
N, K = list(map(int,input().split()))
import math
# A = list(map(int,input().split()))
# pos1 = A.index(1)
t = 1 + math.ceil(float(N-K)/float(K-1))
print(t)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if (N-1) % (K-1) == 0:
    print((N-1)//(K-1))
else:
    print((N-1)//(K-1)+1)

Submission status: Accepted

Solution code:
n,k=input().split()
n,k=[int(n),int(k)]
a=[int(i)for i in input().split()]
i=1
c=0
while i<=n:
    c+=1
    i+=(k-1)
    if i==n:
        break
print(c)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

m = 1
while True:
    if m*k - (m-1) >= n:
        print(m)
        break
    else:
        m += 1

Submission status: Accepted

Solution code:
n, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]

index = 0
for i in range(n):
    if a[i] == 1:
        index = i
        break

count_1 = index
count_2 = n - index -1

r = count_1 % (k-1)
if r == 0:
    q_1 = count_1 // (k-1)
else:
    q_1 = count_1 // (k-1) + 1

if r == 0:
    count_3 = count_2
else:
    count_3 = count_2 - ((k-1) - r)

if count_3 < 0:
    q_2 = 0
elif count_3 % (k-1) == 0:
    q_2 = count_3 // (k-1)
else:
    q_2 =  count_3 // (k-1) +1

ans = q_1 + q_2

print(int(ans))

Submission status: Accepted

Solution code:
def solve():
    n, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    if n == k:
        return 1
    k = k - 1
    ans = 0
    if k == 1:
        return n - 1
    if n % 2 == 1 and k == 2:
        return int((n - 1) / k)
    if n % k == 0:
        ans = int(n / k)
    else:
        ans = int(n / k) + 1
    return ans


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
for i in range(100000):
    if (i-1) * K - (i - 2) < N <= i * K - (i - 1):
        res = i
        break
print(res)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=min(a)
mc=sum([x == m for x in a])
nc=n-mc
print((nc+k-2)//(k-1))

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))


def count(num, k):
    if num == 0:
        return 0
    elif num % (k - 1) == 0:
        return num // (k - 1)
    else:
        return num // (k - 1) + 1


min_index = a_list.index(1)
res = []
for i in range(k):
    pre_end_index = max(min_index - (k-1) + i, 0)
    suf_start_index = min(min_index + i, n-1)
    pre = count(pre_end_index, k)
    suf = count(n-1-suf_start_index, k)
    res.append(pre+suf+1)

print(int(min(res)))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# perm = list(map(int, input().split()))

# print(N)
# print(K)
# print(perm)

n = N
ret = 0

n = n - K
ret += 1

while n > 0:
    n = n - (K - 1)
    ret += 1

print(ret)
#    print(int((N - 1) / (K - 1)))

Submission status: Accepted

Solution code:
from math import ceil

N,K = map(int,input().split())
A = list(map(int,input().split()))

idx = 0
ans = 0
while idx < N - 1:
    ans += 1
    idx += K - 1

print(ans)

Submission status: Accepted

Solution code:
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

a = math.ceil((N - K) / (K - 1))
print(a + 1)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
A = map(int, input().split())
print(-(-(N-1)//(K-1)))

Submission status: Accepted

Solution code:
import sys
import math

imp = raw_input().strip().split(" ")
a = raw_input().strip().split(" ")
N = int(imp[0])
K = int(imp[1])
cnt = 0

while N > K :
    N = N - K + 1
    cnt += 1
print(str(cnt+1))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
an = list(map(int, input().split()))

z = k
cnt = 1
while True:
    if z >= n:
        break
    z = (z - 1) + k
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N,K = (int(i) for i in input().split())
a = [int(x) for x in input().split()]

b= a.index(1)+1

if b/(K-1) == 0:
    answer = -(-(N-1)//(K-1)) +1

else:
    answer = -(-(N-1)//(K-1))

print(answer)

Submission status: Accepted

Solution code:
n,k=map(int,input().strip().split())
c=n
l=list(map(int,input().strip().split()))
ans=0
if n==k:
    print(1)
else:
    while True:
        if n<=0 or n==1:
            break 
        else:
            n=n-(k-1)
            ans+=1
    print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if cnt==0:
        n=n-k
        cnt+=1
        
    else:
        n=n-(k-1)
        cnt+=1
        
    if n<=0:
        break
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n,k = map(int, input().split())
a = [int(i) for i in input().split()]
x=n
for i in range(n):
    if a[i] == 1:
        x=i
        break

y = n - x - 1

p = (x-1)//(k-1) + (y-1)//(k-1) + 2
if (n-1) % (k-1) == 0:
    q = (n-1)//(k-1)
else:
    q = (n-1)//(k-1)+1

print(min(p,q))

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
A_N  = map(int, raw_input().split())
sum = 0

N_m_K     = N - K
N_m_K_div = (N_m_K - 1) / (K - 1)
#div   = N/K
#rem   = N%K

if N == K:
    print 1
else:
    print (N_m_K_div + 1) + 1

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
# print(n, k, a)
if n == k:
    print(1)
elif (n-k)%(k-1) == 0:
    print((n-k)//(k-1)+1)
else:
    print((n-k)//(k-1)+2)

Submission status: Accepted

Solution code:
import math

def f(n, k):
    if n == k:
        return 1
    return math.ceil((n-k)/(k-1)) + 1

N, K = [int(i) for i in input().split()]
A = input()

print(f(N, K))

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 1の位置を見つける
A_1 = A.index(1)

# １回目の1の位置に応じて、計算変わるはず。
result = N
for i in range(K):
    # 1回目の操作
    tmp = 1
    left_d = A_1 - i
    right_d = N - A_1 - 1 - ( K - i - 1)
    
    # 左側
    while left_d > 0:
        tmp += 1
        left_d -= K - 1

    # 右側
    while right_d > 0:
        tmp += 1
        right_d -= K - 1
    
    if tmp < result:
        result = tmp

print(result)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
A = input()


if (N - 1) % (K - 1) == 0:
    print((N - 1) // (K - 1))
else:
    print((N - 1) // (K - 1) + 1)

Submission status: Accepted

Solution code:
def fun(n, m):
    key = 1
    n -= m
    key += n / (m - 1)
    if int(key) == key:
        return int(key)
    else:
        return int(key) + 1
    
N, K = map(int, input().split())
A = list(map(int, input().split()))
key = N / (K - 1)
print(fun(N, K))

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
min_idx = A.index(1)

buff = []
for i in range(K):
    before = min_idx - i
    after = N - (min_idx+1) - (K-1 - i)

    b = int(before / (K-1))
    a = int(after / (K-1))
    if (before % (K-1)) != 0:
        b += 1
    if (after % (K-1))!= 0:
        a += 1

    buff.append(a + b + 1)
print(min(buff))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math

# スペース区切りの整数の入力
n, k = map(int, input().split())
a = map(int, input().split())

# 出力
print(math.ceil((n-k)/(k-1))+1)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
input()
if (N-1) % (K-1) == 0:
    print((N-1) // (K-1))
else:
    print((N-1) // (K-1) + 1)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N != K:
    print((-(-(N-K) // (K-1))) + 1)
else:
    print(1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
sum = K
ans = 0

while 1:
    ans += 1
    if sum >= N:
        break
    sum += K - 1

print (ans)

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split(" "))
a = map(int, input().split(" "))

# print(int((N - 1)/(K - 1)))

print(math.ceil((N - 1) / (K - 1)))

Submission status: Accepted

Solution code:
import math
N,K=map(int, input().split())
a=list(map(int, input().split()))
a.sort()
where=a.index(1)
R=math.ceil((where)/(K-1))
L=math.ceil((N-where-1)/(K-1))
print(R+L)

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split())

A = list(map(int, input().split()))

#m = A.index(min(A))

print(math.ceil((N-1)/(K-1)))

Submission status: Accepted

Solution code:
def c_minimization(N, K, A):
    import math
    ans = math.ceil((N-K)/(K-1))+1
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(c_minimization(N, K, A))

Submission status: Accepted

Solution code:
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

pos = A.index(1) + 1

if (N - 1) % (K - 1) == 0:
    ans = (N - 1) // (K - 1)
else:
    ans = ((N - 1) // (K - 1)) + 1

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
x=k-1
y=n-1
c=y%x
if c==0:
    z=y/x
else:
    z=(y-c)/x+1
print(int(z))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
	if a[i]==1:
		break
p=i
k-=1

#print(ans)
x=0
for j in range(n-1,p,-k):
	x+=1
#print(x)
for j in range(0,p,k):
	x+=1
y=p%k+1+(n-p-1)%k
if p%k>0 and (n-p-1)%k>0 and y<=k+1:
	x-=1
print(x)

Submission status: Accepted

Solution code:
from math import ceil
N, K = map(int,input().split())
_ = input()
print(ceil((N-1)/(K-1)))