Problem:
Score : 300 points

Problem Statement

You are given an integer N.

For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.

For example, F(3,11) = 2 since 3 has one digit and 11 has two digits.

Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

Constraints

1 \leq N \leq 10^{10}

N is an integer.

Input

The input is given from Standard Input in the following format:

N

Output

Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

Sample Input 1

10000

Sample Output 1

3

F(A,B) has a minimum value of 3 at (A,B)=(100,100).

Sample Input 2

1000003

Sample Output 2

7

There are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.

Sample Input 3

9876543210

Sample Output 3

6

Solution in Kotlin (1.0.0) (judge verdict: Wrong Answer)

fun main(args: Array<String>) {
    val n = readLine()?.toLong() ?: return
    if (isPrime(n)) {
        println("$n".length.toString())
        return
    }
    val primes = mutableListOf<Long>()
    var i = 0
    var prime = generatePrime(i)
    var remain = n
    while (remain != 1L) {
        if (isPrime(remain)) {
            primes.add(remain)
            remain = 1L
        }
        if (remain % prime == 0L) {
            remain /= prime
            primes.add(prime)
        } else {
            i++
            prime = generatePrime(i)
        }
    }
    var a = 1L
    var b = 1L
    primes.sortedDescending().forEach {
        if (a > b) {
            b *= it
        } else {
            a *= it
        }
    }
    val length = Math.max(a.toString().length, b.toString().length)
    println(length.toString())
}

val memo = hashMapOf<Int, Long>()
fun generatePrime(index: Int): Long {
    if (index == 0) {
        return 2
    }
    if (index == 1) {
        return 3
    }
    memo[index]?.let {
        return it
    }
    val prev = generatePrime(index - 1)
    var next = prev + 2
    var i = 0
    var prime = 0L
    var l = Math.sqrt(next.toDouble()).toLong()
    while (i < index - 1 && l > prime) {
        prime = generatePrime(++i)
        if (next % prime == 0L) {
            next += 2
            i = 1
            l = Math.sqrt(next.toDouble()).toLong()
        }
    }
    memo[index] = next
    return next
}

fun isPrime(candidate: Long): Boolean {
    var i = 0
    var prime = 0L
    val l = Math.sqrt(candidate.toDouble()).toLong()
    while (l > prime) {
        prime = generatePrime(++i)
        if (candidate % prime == 0L) {
            return false
        }
    }
    return true
}