def countPF(n):
    maxnum=int(n**0.5)
    result=set()
    divisor=2
    while divisor<=maxnum and n>1:
        if not n%divisor:
            n=n//divisor
            result.add(divisor)
            divisor=2
        else: divisor+=1
    if n>1: result.add(n)
    return str(len(result))

total=[]
for i in range(5):
    total.append(input())
for line in total:
    line=line.split()
    number,p=line[0],int(line[1])
    pth=int(number[len(number)-p])
    result=""
    for i in range(len(number)-p):  
        add=str(int(number[i])+pth)
        result+=add
    result+=countPF(int(number))
    for i in range(len(number)-p+1,len(number)):
        result+=str(abs(pth-int(number[i])))
    print(result)