FZU 2238 Daxia & Wzc's problem

Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题:

Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d;

首先让Daxia求出数列A(0)前n项和,得到新数列A(1);

然后让Daxia求出数列A(1)前n项和,得到新数列A(2);

接着让Daxia求出数列A(2)前n项和,得到新数列A(3);

...

最后让Daxia求出数列A(m-1)前n项和,得到新数列A(m);

Input

测试包含多组数据,每组一行,包含四个正整数a(0<=a<=100),d(0<d<=100),m(0<m<=1000),i(1<=i<=1000000000).

Output

每组数据输出一行整数,数列A(m)的第i项mod1000000007的值.

Sample Input
1 1 3 4
Sample Output
35
Hint

A(0): 1 2 3 4

A(1): 1 3 6 10

A(2): 1 4 10 20

A(3): 1 5 15 35

So the 4th of A(3) is 35.


找规律,确定第m,i项有几个a和d,然后排列组合计算一下就好了,因为m很小,直接循环就行。

#include<cmath>  
#include<queue>  
#include<cstdio>  
#include<cstring>  
#include<algorithm>  
using namespace std;
#define ms(x,y) memset(x,y,sizeof(x))  
#define rep(i,j,k) for(int i=j;i<=k;i++)  
#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])  
#define inone(x) scanf("%d",&x)  
#define intwo(x,y) scanf("%lld%lld",&x,&y)  
#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)  
#define lson x<<1,l,mid  
#define rson x<<1|1,mid+1,r  
typedef long long LL;
const int mod = 1e9 + 7;
LL a, d, n, m;

LL inv(LL x)
{
	return x == 1 ? 1 : inv(mod%x)*(mod - mod / x) % mod;
}

LL C(LL x, LL y)
{
	LL res = 1;
	rep(i, 1, y)
	{
		(res *= (x - i + 1) % mod) %= mod;
		(res *= inv(i)) %= mod;
	}
	return res;
}

int main()
{
	while (intwo(a, d), intwo(m, n) != EOF)
	{
		printf("%lld\n", (C(n + m - 1, m)*a + C(n + m - 1, m + 1)*d) % mod);
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值