Leaderboard
Showing:
K-Ary Tree
Easy Accuracy: 29.4% Submissions: 2759 Points: 2

Find the number of leaf nodes in a full k-ary tree of height m.

Input:
First line contains an integer T, number of test cases. Each line of the test case contains two integer k and m.

Output:
Print the number of leafs under modulo 10^9+7.

Constraints:
1<=T<=10^4
1<=k<=100
0<=m<=1000

Example:
Input

1
2 2
Output:
4

Explanation:
A full Binary tree of height 2 has 4 leaf nodes.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

K-Ary Tree

Output Window