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 ...
随机推荐
- TypeScript开发程序
使用TypeScript开发程序 简介 TypeScript一直发展不错,我们公司在开发新功能时,考虑到程序的可维护性,使用了TypeScript编写浏览器上的程序,我们是从零开始使用TypeScri ...
- java中除去字符串(String)中的换行字符(\r \n)
有时在文本框中输入内容特别是粘贴内容时会出现一些换行符(\r\n),如下,在做字数验证或保存到数据库中时应过滤掉. str.replaceAll("\r|\n","&qu ...
- ASP.NET MVC2.0学习笔记:路由设置
Route设置 在 <Professional in ASP.NET MVC2.0>一书的第四章,主要讲述了Route的简单设置.格式化设置.约束设置.区域路由.匹配文件.路由调试以及对R ...
- WP中一些耗时的东西
MediaPlayer.GameHasControl 耗时1.5ms MediaPlayer.State 耗时0.4ms 上面两个原本放在游戏的update中,后来注释掉发现其它的游戏逻辑只要0.2m ...
- Html中DIV成为超级链接,解决在360浏览器+IE9显示小手图标的兼容性!
Html中DIV成为超级链接,解决在360浏览器+IE9显示小手图标的兼容性! <div style="cursor:pointer;" onclick="sele ...
- src设置变量
从后台得到一个图片路径,想把它设置给某个img的src属性,发现直接用$("#").attr("src",data)时src,jquery自己会在这个变量外面添 ...
- linux环境变量入门
一.概要 本文用java环境变量配置这个案例来介绍linux下的环境变量是怎样的,并且和windows系统下的环境变量语法进行了相应对比,适合初学者入门.在这之前,我已经将jdk.tomcat和ecl ...
- .net Mongo Driver 1.0与2.0的对比与2.0的优化
前言 最近闲的时间有点多,所以还是写博客吧. 有人说Mongo 2.0的写法难以把控,好多地方不知道咋用,所以坚持用1.0(不愿意去尝试2.0),我感觉不可理解.所以写篇博客比较下. Mongo C# ...
- Linux编程之给你的程序开后门
这里说的"后门"并不是教你做坏事,而是让你做好事,搭建自己的调试工具更好地进行调试开发.我们都知道,当程序发生异常错误时,我们需要定位到错误,有时我们还想,我们在不修改程序的前提下 ...
- RocketMQ源码 — 二、 NameServer
NameServer 作用:Producer和Consumer获取Broker的地址 目的:解耦Broker和Producer.Consumer 原理:使用netty作为通信工具,监听指定端口,如果是 ...