FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)
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专场之过四题方有奖)的更多相关文章
- FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)
Problem A Daxia & Wzc's problem Accept: 42 Submit: 228Time Limit: 1000 mSec Memory Limit : ...
- 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 ...
- 2016年12月30日 星期五 --出埃及记 Exodus 21:25
2016年12月30日 星期五 --出埃及记 Exodus 21:25 burn for burn, wound for wound, bruise for bruise.以烙还烙,以伤还伤,以打还打 ...
- 2016年12月29日 星期四 --出埃及记 Exodus 21:24
2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...
- 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,若有 ...
- 2016年12月27日 星期二 --出埃及记 Exodus 21:22
2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...
- 2016年2月16日开始,每天一篇,记录学习心得,【基本技能篇】>>开篇《如何阅读一本书——心得》
如何阅读一本书——心得 ——2016年2月12日 要达到阅读的所有目的,就必须在阅读不同书籍的时候,运用适当的不同速度.读的太快或太慢,都一无所获. 四个阅读层次:①基础阅读,具有基本阅读的能力,包括 ...
- Python array,list,dataframe索引切片操作 2016年07月19日——智浪文档
array,list,dataframe索引切片操作 2016年07月19日——智浪文档 list,一维,二维array,datafrme,loc.iloc.ix的简单探讨 Numpy数组的索引和切片 ...
- c++中变量声明和变量定义的区别。2016年12月6日
整个流程: 1.程序告诉cpu,程序将要使用一个变量.(暂时不一定用到,先说一下.) 2.程序告诉CPU,程序现在就要使用一个变量.(现在就用) 3.cpu按照这个变量的类型,把内存划分出几个单位(b ...
随机推荐
- Oracle 11g rac 添加新节点测试
[转]https://blog.csdn.net/shiyu1157758655/article/details/60877076 前期准备: 操作系统设置OS版本必须相同,检查内核参数,系统内存.C ...
- 利用git向github上远程提交一个自己的开源项目
1.在电脑的系统变量中的path路径中配置git的环境变量: 找到git安装路径中bin的位置,如:X:\Git\bin 找到git安装路径中git-core的位置,如:X:\Git\libexec\ ...
- php利用自定义key,对数据加解密的方法
客户端和服务端通信时,有个场景很常见,通过一个id作为url参数来回传递.假设现在业务上只有这个id标识,那么需要稍微安全一点的通信,对这个id进行加密传输,到服务端再进行解密.这里需要一个服务端进行 ...
- LOJ500 ZQC的拼图 二分答案、DP
传送门 题意:给出$N$个直角三角形拼图和$M \times M$的网格,第$i$个直角三角形水平直角边边长为$\frac{1}{a_i}$,垂直直角边边长为$\frac{1}{b_i},$规定直角三 ...
- Luogu3164 CQOI2014 和谐矩阵 异或高斯消元
传送门 题意:给出$N,M$,试构造一个$N \times M$的非全$0$矩阵,其中所有格子都满足:它和它上下左右四个格子的权值之和为偶数.$N , M \leq 40$ 可以依据题目中的条件列出有 ...
- Can't connect to MySQL server (10060)
前天刚装的MySql,今天再次使用就出现了标题显示的错误.我是本地机器连接Linux下的MySql. 网上有一些解决方案: 方法一.检查本地的防火墙 如果是如上状态,请关闭防火墙再试. 方法二.检查服 ...
- hibernate 4 需要导入的jar包
<!-- 下面是导入 hibernate 必须的 jar 包 --> <!-- https://mvnrepository.com/artifact/antlr/antlr --&g ...
- html5录音支持pc和Android、ios部分浏览器,微信也是支持的,JavaScript getUserMedia
以前在前人基础上重复造了一个网页录音的轮子,顺带把github仓库使用研究了一下,扔到了github上. 优势在于结构简单,可插拔式的录音格式支持,几乎可以支持任意格式(前提有相应的编码器):默认提供 ...
- 基于vue2.0 +vuex+ element-ui后台管理系统:包括本地开发调试详细步骤
效果演示地址, github地址: demo演示: 1.About 此项目是 vue2.0 + element-ui + node+mongodb 构建的后台管理系统,所有的数据都是从 ...
- Jenkins持续集成构建自动化测试项目
1.配置内容安全策略(配置一次): 1.1.构建一个自由风格的软件项目 1.2.Build Triggers:Build when job nodes start 1.3.Build:Execute ...