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

Bad Serial Inc.

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


Problem Description
Bad Serial Inc. (BSI) produces integer sequences with length N, in which every element is an integer in range [1, M].
They call a sequence S is bad if all the M-substrings (substrings with length M) are bad.
They call an M-substring is bad if it¡¯s not good. An M-substring is good if all the elements in the substring are the same or all the elements are distinct (different from each other).
The company BIS is designed to produce bad sequences. But how many different bad sequences are there? Since the answer will be very large, just output the result after module 987654321.

 

Input
There are several cases. For each case, there is a line with two integers N, and M (1 ¡Ü N ¡Ü 100, 1 ¡Ü M ¡Ü 9).
The input ends up with two negative numbers, which should not be processed as a case.
 

Output
Print the number of different bad sequences module 987654321 in a line for each case.

 

Sample Input
4 4 3 5 -1 -1
 

Sample Output
228 125
 

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-25 23:10:14, Gzip enabled