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. zabbix_agent安装

    #!/bin/bash#by Charon2Pluto#(linux)ML=`df |awk '{print $2,$NF}'|sort -n|tail -1|awk '{print $2}'` if ...

  2. oracle备份恢复之recover database的四条语句区别

    1  recover database using backup controlfile2  recover database until cancel3  recover database usin ...

  3. PAT A1026 Table Tennis (30 分)——队列

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

  4. Echo团队Alpha冲刺随笔 - 第四天

    项目冲刺情况 进展 前端:完成了差不多一半,小程序部分界面基本完工,WEB端也完成了一部分 后端:也完成了大半了 问题 后端文件上传还没解决 心得 进度还行,团队配合都还不错 今日会议内容 黄少勇 今 ...

  5. C语言程序设计II—第四周教学

    第四周教学总结(18/3-24/3) 教学内容 本周的教学内容为:第七章 数组 7.2 二维数组 课前准备 在博客园发布作业:2019春第四周作业 第三周作业讲解视频:A Programing Vid ...

  6. javaweb1(小学生四则运算)

    一.设计思想 ①设计三个页面,分别为题数设置页面,题目显示页面以及结果显示页面. ②设计题数设置页面. ③从题数设置页面接收题数,作为循环次数. ④利用随机数生成相应符合条件表达式,并存入数据库. ⑤ ...

  7. day83

    今日内容 rest_framework序列化 首先序列化需要对写一个类继承serializers.Serializer 方式一:在models的publish写一个__str__方法返回出版社名字 p ...

  8. mac安装CocoaPods遇到的问题及解决办法

    (1)sudo gem install cocoapods Fetching: i18n-0.7.0.gem (100%) Successfully installed i18n-0.7.0 Fetc ...

  9. C#路径的八种相关操作,判断字符串是否为路径等

    原文:C#路径的八种相关操作,判断字符串是否为路径等 1.判定一个给定的C#路径是否有效,合法 通过Path.GetInvalidPathChars或Path.GetInvalidFileNameCh ...

  10. 面试4——java进程和线程相关知识

    1.线程和进程的概念.并行和并发的概念