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
Alien: 2013-07-26 01:56:50

tutorial task

Rudradeep Mukherjee: 2013-07-24 12:40:03

The answer to the 2nd test case is wrong. The correct answer is 626248230.

Miguel Oliveira: 2013-07-23 22:28:26

I don't know if I over-complicated my solution.
For those of you saying this should be moved to tutorial, is O(L) per test case enough for this problem?

My approach is O(log L) and involves the modular inverse which doesn't seem tutorial stuff to me. Maybe I didn't think of a simpler, but fast solution.

Shaka Shadows: 2013-07-23 21:02:27

This one should be moved to tutorials.

Miguel Oliveira: 2013-07-23 09:29:02

I assumed there was a large number of test cases. If the number of test cases is 10 000 or 100 000 this is not trivial imo.

Akash: 2013-07-23 07:43:31

Tutorial task!!!


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