Best Divisor

0

0 votes
Easy
Problem

Kristen loves playing with and comparing numbers. She thinks that if she takes two different positive numbers, 
the one whose digits sum to a larger number is better than the other. If the sum of digits is equal for both 
numbers, then she thinks the smaller number is better. For example, Kristen thinks that 13 is better than 31 
and that 12 is better than 11.

Given an integer, n, can you find the divisor of n that Kristin will consider to be the best?

Input Format:
    A single integer n denoting .

Constraints:
    0<n<=10^5


Output Format
    Print an integer denoting the best divisor of n.

Sample input:
12

Sample output:
6

Explanation:
The set of divisors of 12 can be expressed as {1,2,3,4,6,12}. The divisor whose digits sum to the largest number is 6 (which, having only 
one digit, sums to itself). Thus, we print 6 as our answer.

Time Limit: 1
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?