FZU 2238 Daxia & Wzc's problem
公式。
$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 ;
}
FZU 2238 Daxia & Wzc's problem的更多相关文章
- FZU Problem 2238 Daxia & Wzc's problem
Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...
- 【数论】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 ...
- FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)
Problem A Daxia & Wzc's problem Accept: 42 Submit: 228Time Limit: 1000 mSec Memory Limit : ...
- FZU 2240 Daxia & Suneast's problem
博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...
- FZU 2224 An exciting GCD problem(GCD种类预处理+树状数组维护)同hdu5869
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2224 同hdu5869 //#pragma comment(linker, "/STACK:1024 ...
- FZU - 2038 -E - Another Postman Problem (思维+递归+回溯)
Chinese Postman Problem is a very famous hard problem in graph theory. The problem is to find a shor ...
- FZU 2243 Daxia like uber
枚举,最短路. 求出5个点出发的最短路,然后枚举一下这些点之间走的顺序. #pragma comment(linker, "/STACK:1024000000,1024000000" ...
- HITtrainning20140417题解
题目列表: ID Origin Title 10 / 15 Problem A FZU 2152 文件系统 0 / 16 Problem B FZU 2153 A simple geome ...
随机推荐
- 在 Emacs 中如何退出 Slime Mode
1.在 Slime 的 Buffer 中按逗号“,”: 2.在 Command 后输入:sayoonara 3.回车,确认. ================ 退出 SBCL 输入:(sb-ext:q ...
- JS事件冒泡、停止冒泡、addEventListener--实例演示
问题: <div class='item' id='outer' onclick="alert('outer')"> <div class='item' id=' ...
- 《C++游戏开发》笔记十二 战争迷雾:初步实现
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9475979 作者:七十一雾央 新浪微博:http:/ ...
- MVP社区巡讲
MVP社区巡讲照片集 今天MVP社区巡讲在北京利星行微软大厦连同SQL PASS社区合办了一次线下活动,这次互动汇集了在北京大多数的微软MVP,他们都是微软认可的有着各微软产品和技术特长的技术专家,无 ...
- web register/validation/login system flowchart
I spent several days on building a system about this. And make it work well with serveral thousand l ...
- 使用Freemarker创建word文档
最近做一个项目,本来是直接在网页上查看文本信息,然后给客户直接打印的,但是发现也许是浏览器还是打印机的原因,总之,有个客户打印出来的格式始终与其他的不同,没办法,最后想到了直接将数据库中的信息生成一个 ...
- Java构造器的深入理解
[构造器与方法的深入理解] 构造器的深入理解 [博主]高瑞林 [博客地址]http://www.cnblogs.com/grl214 [博客地址]http://www.cnblogs.com/grl2 ...
- 转载 C#文件上传
一.分析 本次博客,主要解决文件上传等一系列问题,将从两方面来论述,即1G以内文件和1G以上文件. 对于上传1G以内的文件,可以采用基本的三种上传方法:用Web控件FileUpload.html控件 ...
- C++11多线程std::thread的简单使用
在cocos2dx 2.0时代,我们使用的是pthread库,是一套用户级线程库,被广泛地使用在跨平台应用上.但在cocos2dx 3.0中并未发现有pthread的支持文件,原来c++11中已经拥有 ...
- HDU 4777 Rabbit Kingdom
素因子分解,树状数组.$ACM/ICPC$ $2013$杭州区域赛$H$题. 首先需要处理出数字$a[i]$左边最远到$L[i]$,右边最远到$R[i]$区间内所有数字都与$a[i]$互质. 那么对于 ...