Problem A Daxia & Wzc's problem

Accept: 42    Submit: 228
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

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.
Cached at 2016-08-17 19:08:15.

 
草稿纸上手写一下
a1  a1+d  a1+2d  a1+3d...
a1  2a1+d  3a1+3d  4a1+6d...
a1  3a1+d  6a1+4d  10a1+10d...
...
可以发现这个是一个类似杨辉三角的东西,大概就是C(n, m)这样算的。
然后就用Lucas就行了
 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e3 + ;
LL mod = 1e9 + ;
LL f[N]; LL Pow(LL a , LL n , LL mod) {
LL res = ;
while(n) {
if(n & )
res = res * a % mod;
a = a * a % mod;
n >>= ;
}
return res;
} LL Comb(LL a , LL b , LL mod) {
if(a < b) {
return ;
}
if(a == b) {
return ;
}
LL ca = ;
for(LL i = ; i < b ; i++) {
ca = (a - i) % mod * ca % mod;
}
return (ca * f[b]) % mod;
} LL Lucas(LL n , LL m , LL mod) {
LL ans = ;
while(m && n && ans) {
ans = (ans * Comb(n % mod , m % mod , mod)) % mod;
n /= mod;
m /= mod;
}
return ans;
} int main()
{
f[] = ;
for(LL j = ; j < N; ++j) {
f[j] = j * f[j - ] % mod; //阶乘
}
for(LL j = ; j < N; ++j) {
f[j] = Pow(f[j], mod - , mod); //逆元
}
LL a, b, m, i;
while(cin >> a >> b >> m >> i) {
if(i == ) {
cout << a << endl;
continue;
}
LL x = Lucas(m + i - , m, mod) * a % mod;
LL y = Lucas(m + + i - , m + , mod) * b % mod;
cout << (x + y) % mod << endl;
}
return ;
}

FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)的更多相关文章

  1. FZU Problem 2238 Daxia & Wzc's problem

    Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...

  2. FZU 2238 Daxia & Wzc's problem

    公式. $a×C_{m + i - 1}^m + d×C_{m + i - 1}^{m + 1}$. 推导过程可以看http://blog.csdn.net/queuelovestack/articl ...

  3. 【数论】FOJ 2238 Daxia & Wzc's problem

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类 ...

  4. Problem 2238 Daxia & Wzc's problem 1627 瞬间移动

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...

  5. FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)

    http://acm.fzu.edu.cn/contest/list.php?cid=152 主要是a题, lucas定理, 就这一版能过..  记录一下代码, 另外两个最短路  一个模拟,没什么记录 ...

  6. FZU 11月月赛D题:双向搜索+二分

    /* 双向搜索感觉是个不错的技巧啊 */ 题目大意: 有n的物品(n<=30),平均(两个人得到的物品差不能大于1)分给两个人,每个物品在每个人心目中的价值分别为(vi,wi) 问两人心目中的价 ...

  7. FZU 2240 Daxia & Suneast's problem

    博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...

  8. FZU 2139——久违的月赛之二——————【贪心】

    久违的月赛之二 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  9. FZU 2138——久违的月赛之一——————【贪心】

    久违的月赛之一 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

随机推荐

  1. Spring Transaction属性之Propagation

    spring Transaction中有一个很重要的属性:Propagation.主要用来配置当前需要执行的方法,与当前是否有transaction之间的关系. 我晓得有点儿抽象,这也是为什么我想要写 ...

  2. Python内置数据类型之Tuple篇

    Tuple 是不可变的 list.一旦创建了一个 tuple,就不可以改变它.这个有点像C++中的const修饰的变量.下面这段话摘自Dive Into Python: Tuple 比 list 操作 ...

  3. matplotlib 绘制柱状图的几个例子

    1 error bar #!/usr/bin/env python # a bar plot with errorbars import numpy as np import matplotlib.p ...

  4. (六) 语言模型 Language Madel 与 word2vec

    语言模型简介(Language Model) 简单的说,语言模型 (Language Model) 是用来计算一个句子出现概率的模型,假设句子  ,其中  代表句子中的第  个词语,则语句 W 以该顺 ...

  5. 【英语】Bingo口语笔记(68) - come系列

  6. 修改Chrome默认搜索引擎为Google.com

    在使用Chrome的时候,Google为增强本地化搜索,或将默认的Google搜索引擎转换为本地语言,如在中国会自动转到google.com.hk,日本会会自动转到google.co.jp,如果你是一 ...

  7. ORACLE 临时表空间清理

    Oracle临时表空间主要用来做查询和存放一些缓冲区数据.临时表空间消耗的主要原因是需要对查询的中间结果进行排序.临时表空间的主要作用: 索引create或rebuildOrder by 或 grou ...

  8. linux 下安装flash player

    或者直接下载:i386系统wget http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpmrp ...

  9. [Papers]MHD, $\p_3\pi$, Lebesgue space [Cao-Wu, JDE, 2010]

    $$\bex \p_3\pi\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=\frac{12}{7},\quad \frac{12}{7} ...

  10. 让jquery.tmpl.js支持index序号

    在写Web程序时,想简单处理会使用JS模板,常用的是Jquery的jquery.tmpl.js插件.整个插件还是比较好用的,后续有机会结合实际应用案例,分享下应用方法. 本次文章想分享的一点是其中的一 ...