http://acm.fzu.edu.cn/contest/list.php?cid=152

主要是a题, lucas定理, 就这一版能过..  记录一下代码, 另外两个最短路  一个模拟,没什么记录价值.

 //#define txtout
//#define debug
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double eps=1e-;
const int inf=0x3f3f3f3f;
//const int M=1e7+10; LL pow_mod (LL a, LL n, LL p) {
LL ans = ,t = a;
while (n) {
if (n & ) {
ans = ans * t % p;
}
t = t * t % p;
n >>= ;
}
return ans;
}
LL cal (LL n, LL m, LL p) {
if(m > n-m) m = n - m;
LL ans = ;
for (int i = ; i <= m; i++) {
ans = ans * (n - i + ) % p;
int a = pow_mod(i,p-,p);
ans = ans * a % p;
}
return ans;
}
LL com_mod (LL n,LL m,LL p) {
if (n < m)return ;
return cal(n,m,p);
}
LL lucas (LL n, LL m, LL p) {
LL r = ;
while(n && m && r) {
r = r *com_mod(n%p, m%p, p) % p;
n /= p;
m /= p;
}
return r;
} LL a,d,m,n;
//int c[M];
//LL C(int n,int m) {
// LL result=1;
// for(int i=0; i<m; i++) {
// result*=(n-i);
// }
// for(int i=0; i<m; i++) {
// result/=(1+i);
// }
// return result;
//}
const LL MOD=;
LL solve() {
if(n==){
return a;
}
LL answer=lucas(m+n-,n-,MOD)*a%MOD;
if(n->=) answer+=lucas(m+n-,n-,MOD)*d%MOD;
answer%=MOD;
return answer;
}
int main() {
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // txtout
// num=sieve(MAXN);
while(~scanf("%I64d%I64d%I64d%I64d",&a,&d,&m,&n)) {
printf("%I64d\n",solve());
}
return ;
}

end

FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)的更多相关文章

  1. FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)

    Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : ...

  2. 2016年12月31日 星期六 --出埃及记 Exodus 21:26

    2016年12月31日 星期六 --出埃及记 Exodus 21:26 "If a man hits a manservant or maidservant in the eye and d ...

  3. 2016年12月30日 星期五 --出埃及记 Exodus 21:25

    2016年12月30日 星期五 --出埃及记 Exodus 21:25 burn for burn, wound for wound, bruise for bruise.以烙还烙,以伤还伤,以打还打 ...

  4. 2016年12月29日 星期四 --出埃及记 Exodus 21:24

    2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...

  5. 2016年12月28日 星期三 --出埃及记 Exodus 21:23

    2016年12月28日 星期三 --出埃及记 Exodus 21:23 But if there is serious injury, you are to take life for life,若有 ...

  6. 2016年12月27日 星期二 --出埃及记 Exodus 21:22

    2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...

  7. 2016年2月16日开始,每天一篇,记录学习心得,【基本技能篇】>>开篇《如何阅读一本书——心得》

    如何阅读一本书——心得 ——2016年2月12日 要达到阅读的所有目的,就必须在阅读不同书籍的时候,运用适当的不同速度.读的太快或太慢,都一无所获. 四个阅读层次:①基础阅读,具有基本阅读的能力,包括 ...

  8. Python array,list,dataframe索引切片操作 2016年07月19日——智浪文档

    array,list,dataframe索引切片操作 2016年07月19日——智浪文档 list,一维,二维array,datafrme,loc.iloc.ix的简单探讨 Numpy数组的索引和切片 ...

  9. c++中变量声明和变量定义的区别。2016年12月6日

    整个流程: 1.程序告诉cpu,程序将要使用一个变量.(暂时不一定用到,先说一下.) 2.程序告诉CPU,程序现在就要使用一个变量.(现在就用) 3.cpu按照这个变量的类型,把内存划分出几个单位(b ...

随机推荐

  1. expdp 高版本导入到低版本

    低版本 往 高版本 导入,导出的时候不用加version : 高版本往低版本的时候 需要加 version expdp version (往低版本的时候 需要加 version 版本号是 impdp ...

  2. 2018AVA: A Video Dataset of Spatio-temporally Localized Atomic Visual Actions

    论文标题:AVA: A Video Dataset of Spatio-temporally Localized Atomic Visual Actions 来源/作者机构情况: 谷歌,http:// ...

  3. QWidget设置背景颜色

    如果widget是子窗口首先要添加一句: this->setAttribute(Qt::WA_StyledBackground,true); this->setStyleSheet(&qu ...

  4. java 学习------helloword 程序测试

    1.新建一个helloword.java  文件 2.在新建的helloword.java 文件中添加以下代码 class helloWord { public static void main(St ...

  5. python游戏开发之俄罗斯方块(一):简版

    编程语言:python(3.6.4) 主要应用的模块:pygame (下面有源码,但是拒绝分享完整的源码,下面的代码整合起来就是完整的源码) 首先列出我的核心思路: 1,图像由"核心变量&q ...

  6. jquery中的选择器:has和:not的用法

    这两个选择器可以帮助我们在选择父级和子孙之间关系的dom更从容~ <div><p><span>Hello</span></p></di ...

  7. Nowcoder156F 托米的游戏/CF280C Game on tree 期望

    传送门 题意:给出一棵树,在每一轮中,随机选择一个点将它与它的子树割掉,最后割掉所有点时游戏结束,问游戏期望进行多少轮.$N \leq 10^5$ 和的期望等于期望的和,我们考虑每一个点对最后答案的贡 ...

  8. React-UI组件和容器组件

    UI组件负责页面的渲染,又叫傻瓜组件. 容器组件负责逻辑,又叫聪明组件. 当一个组件只有render函数的时候,就可以用无状态组件的形式来定义这个组件.无状态组件怎么定义呢?其实就是一个函数,接受pr ...

  9. Luogu P2059 [JLOI2013]卡牌游戏

    一道比较简单的概率DP 首先看到这种题目和数据范围,就要毫不犹豫地列DP方程: 我们令\(f_{i,j}\)表示还剩下i个人时编号为j的人的胜率,那么首先我们可以知道边界条件\(f_{1,1}=1\) ...

  10. Spring 中配置log4j日志功能

    一,添加log4j依赖包 可从官网上下载该依赖包log4j-x.x.xx.jar,下载后 build path,添加依赖包 二,创建 log4j.properties 配置文件 log4j.prope ...