Kth root problem

Please help me solve this problem! specifically in java, as the site only shows solution in c++.


All test case passed