import math

#returns a list of all prime factors
def primeFactors(n):
  primes = []
  p = 2
  if(n % 2 == 0):
    primes.append(p)
  while(n % 2 == 0):
    n /= p
  p = 3
  while(p < math.sqrt(n) + 1):
    if(n % p == 0):
      primes.append(p)
    while(n % p == 0):
      n /= p
    p += 2
  primes.append(n)
  return primes

#prints transformed number
def numberTransformation(p, N):
  #calculates digits to the left of the pth digit
  for i in range(0,len(N) - p):
    print(N[i] + N[len(N) - p], end = "")

  #calculates the pth digit
  print(len(primeFactors(int(''.join(map(str, N))))), end = "")

  #calculates digits to the right of the pth digit
  for i in range(len(N) - p + 1, len(N)):
    print(abs(N[i] - N[len(N) - p]), end = "")
  
  print()

#
# Takes a file name and then prints out transformed values
# Input a file with at least one line of numbers
#
fileName = input("Enter the name of the file you want to input: ")
f = open(fileName, "r")
for line in f:
  N = []
  p = 0
  for c in line:
    if(c == " "):
      break
    N.append(int(c))
    p += 1
  p = int(line[p:])
  numberTransformation(p, N)