F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Perfect Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 258    Accepted Submission(s): 55


Problem Description
A sequence <a0, a1, a2, ..., an> of integers is called a perfect sequence when all the partial sums a0, a0 + a1, a0 + a1 + a2, ..., a0 + a1 + ... + an are all positive.
Let¢¥s consider a specific sequence <a0, a1, a2, ..., amn>, (ai = 1 or ai = (1-m), 1 ¡Â i ¡Â (m*n) ) , whose total sum is 1. Actually you can easily deduce that there are n occurrences of (1-m). So how many of these sequences are perfect sequences.
 

Input
Input contains several testcases.
For each test case, you will be given n, m (1 ¡Â m, n ¡Â 100000) in a single line.
Process to the end of the file.
 

Output
On each single line, output a number r mod 100000007, r is the number of perfect sequences <a0, a1, a2, ..., amn> (ai = 1 or ai = (1-m), 1 ¡Â i ¡Â (m*n) ) .
 

Sample Input
4 2 5 2 3 4
 

Sample Output
14 42 22
 

Author
jifeifei1989
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-26 07:07:40, Gzip enabled