HDOJ 3482 Good Serial Inc.

描述不清。。。没有意义的水题。。。。

Good Serial Inc.

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 605    Accepted Submission(s): 244


Problem Description
Good Serial Inc. (GSI) produces integer sequences with length N, in which every element is an integer in range [1, M].
They call a sequence S is good if the sequence has the following property: for every substring of S with length M, i.e., S[i -> i+m-1], all the elements in the substring are the same or all the elements are distinct(different from each other).
The company GIS is designed to produce good sequences. But how many different good 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 ≤ 1000000, 1 ≤ M ≤ 1000000 ).
The input ends up with two negative numbers, which should not be processed as a case.

 

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

 

Sample Input
  
  
4 4 3 5 -1 -1
 

Sample Output
  
  
28 125
 

Source
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long int LL;
const LL mod=987654321;

int main()
{
    int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
    if(n==-1&&m==-1) break;
    LL ans=m,jie=1;

    if(m<=2||n<m)
    {
        ans=0;
        for(int i=0;i<n;i++)
        {
            jie=(jie*m)%mod;
        }
        ans=jie;
    }
    else if(n>=m)
    {
        for(int i=1;i<=m;i++)
        {
            jie=(jie*i)%mod;
        }
        ans=(ans+jie)%mod;
    }
    printf("%I64d\n",ans);
}
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值