UCV2013A - Counting Ids


Little Willy just took a compilers course and is trying to implement his own compiler. First he wants to build a table with all the possible ids that a program could have. He knows that his language supports up to N different characters and any id can be up to L characters long. For example, when N = 2 (lets say characters can be 0 or 1), and L = 3, he could have the following ids: {0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111}.

You have to write a program that can help Willy find out the size of the table. Since the answer can be really big, you must print it modulo 1000000007 (10^9+7).

Input

The input contains several test cases. Each test case will consist of a single line containing two integers N and L. N is the number of characters that can be part of an id and L is maximum length supported by the language (1 <= N <= 65535, 1 <= L <= 10^5).

End of the input is indicated by a test case with N = 0, L = 0 that should not be processed.

Output

For each test case output a single line containing the number of possible ids modulo 10^9+7.

Example

Input:
2 3
128 32
0 0 Output: 14
792805767

hide comments
Amitayush Thakur: 2014-06-17 12:46:00

Weak test cases. Doesn't have a test case where N=1.

যোবায়ের: 2014-01-05 20:53:42

Your input file should contain some cases where N = 1. Just saying...

Last edit: 2014-01-05 20:54:08
Himanshu: 2013-09-13 08:06:40

@bigBOSS
not a beginner problem
learn a lot form this problem....

Last edit: 2013-09-13 08:15:34
Miguel Oliveira: 2013-08-02 01:19:28

@Degree of Freedom check http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm it explains the modular inverse

Hitman: 2013-08-01 18:16:14

To my surprise O(L) works fine

Last edit: 2013-08-01 18:16:38
Ouditchya Sinha: 2013-08-01 06:48:39

Easy but certainly not a tutorial problem, increased constraints could make it more challenging. :)

narendray: 2013-07-31 16:15:31

Miguel Oliveira : Any link of Modular inverse regarding the algo.

Anubhav Balodhi : 2013-07-30 14:16:44

What da?!? same code nzec in Python 3.2.3 but ac in python 2.7...

abdelkarim: 2013-07-29 13:51:09

simple but nice math one ;) .

mystique_blue: 2013-07-29 13:22:57

Akash your comment is a spoiler. Please remove it. Discuss in the forum.


Added by:Hector Navarro
Date:2013-07-22
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Local UCV 2013. Héctor Navarro