公式。

$a×C_{m + i - 1}^m + d×C_{m + i - 1}^{m + 1}$。

推导过程可以看http://blog.csdn.net/queuelovestack/article/details/52260127

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} LL a,d,i,m,p; LL quick_mod(LL a, LL b)
{
LL ans = ;
a %= p;
while(b)
{
if(b & )
{
ans = ans * a % p;
b--;
}
b >>= ;
a = a * a % p;
}
return ans;
} LL C(LL n, LL m)
{
if(m > n) return ;
LL ans = ;
for(int i=; i<=m; i++)
{
LL a = (n + i - m) % p;
LL b = i % p;
ans = ans * (a * quick_mod(b, p-) % p) % p;
}
return ans;
} LL Lucas(LL n, LL m)
{
if(m == ) return ;
return C(n % p, m % p) * Lucas(n / p, m / p) % p;
} int main()
{
while(~scanf("%I64d%I64d%I64d%I64d", &a,&d,&m, &i))
{
p=;
printf("%I64d\n", (a*Lucas(m+i-,m)+d*Lucas(m+i-,m+))%p);
}
return ;
}
05-04 06:19