FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)
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
Sample Output
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.
//#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)的更多相关文章
- FZU Problem 2238 Daxia & Wzc's problem
Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...
- 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 ...
- 【数论】FOJ 2238 Daxia & Wzc's problem
题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类 ...
- Problem 2238 Daxia & Wzc's problem 1627 瞬间移动
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...
- FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)
http://acm.fzu.edu.cn/contest/list.php?cid=152 主要是a题, lucas定理, 就这一版能过.. 记录一下代码, 另外两个最短路 一个模拟,没什么记录 ...
- FZU 11月月赛D题:双向搜索+二分
/* 双向搜索感觉是个不错的技巧啊 */ 题目大意: 有n的物品(n<=30),平均(两个人得到的物品差不能大于1)分给两个人,每个物品在每个人心目中的价值分别为(vi,wi) 问两人心目中的价 ...
- FZU 2240 Daxia & Suneast's problem
博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...
- FZU 2139——久违的月赛之二——————【贪心】
久违的月赛之二 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- FZU 2138——久违的月赛之一——————【贪心】
久违的月赛之一 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
随机推荐
- 51nod1122 机器人走方格 V4
矩阵快速幂求出每个点走n步后到某个点的方案数.然后暴力枚举即可 #include<cstdio> #include<cstring> #include<cctype> ...
- 51nod1295 XOR key
第一次写可持久化trie指针版我... //Null 的正确姿势终于学会啦qaq... #include<cstdio> #include<cstring> #include& ...
- IOS中UICollectionView和UICollectionViewController的用法
1.新建一个xib描述UICollectionViewCell(比如DealCell.xib),设置好resuse identifier(比如deal) 2.控制器继承UICollectionView ...
- 点分十进制IP校验、转换,掩码校验
/***************************************************************************** * 点分十进制IP校验.转换,掩码校验 * ...
- mipmap 目录和drawable 目录有什么区别
Q :最近使用studio 发现drawle-hdpi 都没有了换成了mipmap-hdpi,这两个目录有什么区别呢,哪个比较好呢??? A: 我简单总结一下: 使用上没有任何区别,你把它当drawa ...
- RandomAcessFile、MappedByteBuffer和缓冲读/写文件
项目需要进行大文件的读写,调查测试的结果使我决定使用MappedByteBuffer及相关类进行文件的操作,效果不是一般的高. 网上参考资源很多,如下两篇非常不错: 1.花1K内存实现高效I/O的Ra ...
- C#读写文件总结
1.使用FileStream读写文件 文件头: using System; using System.Collections.Generic; using System.Text; using ...
- Python自动单元测试框架
原文链接:http://www.ibm.com/developerworks/cn/linux/l-pyunit/ 软件的测试是一件非常乏味的事情,在测试别人编写的软件时尤其如此,程序员通常都只对编写 ...
- Linux基本命令(10)其他命令
其他命令 命令 功能 命令 功能 echo 显示一字串 passwd 修改密码 clear 清除显示器 lpr 打印 lpq 查看在打印队列中等待的作业 lprm 取消打印队列中的作业 10.1 ec ...
- STL中用erase()方法遍历删除元素 .xml
pre{ line-height:1; color:#f0caa6; background-color:#2d161d; font-size:16px;}.sysFunc{color:#e54ae9; ...