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. [swustoj 243] 又是一年CET46

    又是一年CET46(0243) 问题描述 CET46 成绩出来啦,一群学生在谈论他们的成绩.A说他的成绩比B高,B说他的成绩比C低,D说他的成绩和E一样…… 他们当中可能有人在说谎.你的任务就是判断是 ...

  2. Volley : "参数param:{ inoutNo:inoutNo ,whcode:’’}

    private void fuzzySearch() { mRequestQueue = Volley.newRequestQueue(getActivity()); String str = Sha ...

  3. BZOJ 1984 月下“毛景树”

    我觉得我要把BZOJ上的链剖写完了吧.... #include<iostream> #include<cstdio> #include<cstring> #incl ...

  4. (转)Mac OS X写了个rm时将文件放入回收站的小工具

    上次由于公司里机器要面临重装,开始仓皇地将Mac本里的文件scp到我的台式机上.忙乱之中本来要删除一个无用的文件夹的,结果用rm -rf的时候tab了一下,补全出来的文件都没看清就按下了回车,毫无疑问 ...

  5. swun 1388 你的背包

    解题思路:这题给人的第一反应是背包,第二反应是贪心,我用的是搜索,枚举就可以,要有这种意识, 题目数据只有8个,暴力是可以解决的. #include<cstdio> #include< ...

  6. 【英语】Bingo口语笔记(60) - 口语中的浊化发音

  7. 使用sqlldr将文件中的数据导入到数据库

    1.创建数据文件: ?如,在D:\创建 zhaozhenlong.txt 文件,文件内容为: 11,12,1321,22,2331,32,33 2.创建控制文件: 如,在D:\创建 zhaozhenl ...

  8. Fidder 监控WCF

    Client端配置 <?xml version="1.0" encoding="utf-8" ?> <configuration> &l ...

  9. 嵌入式 Linux下curl库API简单介绍

    1:CURLcode curl_global_init(long flags); 这个函数全局需要调用一次(多次调用也可以,不过没有必要), 所以这也是把Curlplus设计成单体类的原因,curl_ ...

  10. API指南----application

    <application android:allowTaskReparenting=["true" | "false"]    android:allow ...