def numofPrime(num):
    count=0
    for i in range(2,int(num**0.5)+1):
        if num%i==0:
            while num%i==0:
                num=num/i
            count+=1
    if num!=1:count+=1
    return count

output=[]
for i in range(5):
    result=""
    N,P=input().split()
    index=len(N)-int(P)
    for i in range(index):
        result+=str(int(N[i])+int(N[index]))
    result+=str(numofPrime(int(N)))
    for i in range(index+1,len(N)):
        result+=str(abs(int(N[i])-int(N[index])))
    output.append(result)

for i in output:
    print(i)