fun main(args: Array) { val t = readLine()!!.toInt() val ans = java.lang.StringBuilder() repeat(t){ _ -> ans.appendln(getAns(readLine()!!.toLong())) } print(ans.toString()) } fun getAns(num:Long):Long { if(num == 1L) { return 2 } val prime = primeDivide(num) val keys = prime.keys.toList() if(keys.size == 1 && keys.first() == 2L) { return num*3 } var tmp = Long.MAX_VALUE for(i in primeList.indices) { if(keys.size <= i) { tmp = primeList[i] break } if(keys[i] != primeList[i]) { tmp = primeList[i] break } } val total = prime.values.sum() return Math.min(tmp, 1L shl total) * num } val primeList = mutableListOf().also { val max = 1_000_000 val flag = BooleanArray(max+1) for(i in 2..max) { if(flag[i]) { continue } it.add(i.toLong()) for(j in 1..max) { if(i*j>max) { break } flag[i*j] = true } } } fun primeDivide(num:Long):Map { var n = num val ret = mutableMapOf() for(prime in primeList) { if(prime*prime > n) { if(n > 1) { ret[n] = 1 } break } while (n % prime == 0L) { ret[prime] = (ret[prime]?:0)+1 n /= prime } } return ret }