Testing K^K == N?

Published by Helen Yu in

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

Examples

k_to_k(4, 2) ➞ true

k_to_k(387420489, 9) ➞ true
# 9^9 == 387420489

k_to_k(3124, 5) ➞ false

k_to_k(17, 3) ➞ false

Notes

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

Watch a quick demo on how Edabit works.