Company: Texas Instruments_29thjuly
Difficulty: medium
A number p is a Special number if p divided by the sum of its digits gives a prime number. For example, 18 is a Special number because 18 / (1 + 8) = 18 / 9 = 2 , and 2 is prime. Formally, p is Special if the sum of its digits divides p exactly, and the quotient p / digitsum(p) is a prime number. (If the sum of digits does not divide p exactly, p is not Special.) You are given n numbers. For each number, determine how far off the nearest Special number is from it. Read the input from STDIN and print the output to STDOUT. Do not print any strings other than the required output. Constraints 1 <= n <= 2000 10 < value <= 1000 for every given number Input Format The first line of input consists of a single integer n , the count of numbers. The second line of input consists of n space-separated numbers. Output Format Print a single line containing n space-separated integers. For each given number, print nearestSpecial - number , where nearestSpecial is the Special number closest