Testing K^K == N?

Published by Nomore in

Write a function that returns true if k^k == n for input (n, k) and return false otherwise.

Examples

KToK("4", 2) ➞ true

KToK("387420489", 9) ➞ true
# 9^9 == 387420489

KToK("3124", 5) ➞ false

KToK("17", 3) ➞ false

Notes

The ^ operator refers to exponentiation operation, not the bitwise XOR operation.

Watch a quick demo on how Edabit works.