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 ...
随机推荐
- jQuery:自定义函数
<!doctype html><html><head><meta charset="utf-8"><title>< ...
- CVE-2018-14424 use-after-free of disposed transient displays 分析报告
漏洞描述 GDM守护进程不能正确的取消导出在D-Bus 接口上已经被销毁的display对象,这造成本地用户可以触发UAF,从而使系统崩溃或造成任意代码执行. 调试环境 gdm版本: 3.14.2(通 ...
- AI 偏微分方程
1.微分dx: 高阶无穷小 偏微分方程
- java 文件字节和字符流 缓冲流
流的原理 1) 在 Java 程序中,对于数据的输入/输出操作以“流”(stream) 方式进行:2) J2SDK 提供了各种各样的“流”类,用以获取不同种类的数据:程序中通过标准的方法输入或输出数据 ...
- Python崛起:“人生苦短,我用Python”并非一句戏言
这些年,编程语言的发展进程很快,在商业公司.开源社区两股力量的共同推动下,涌现出诸如Go.Swift这类后起之秀,其中最为耀眼的是Python. 在这里还是要推荐下我自己建的Python开发学 ...
- 4.3《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)—链接到目录
在4.2章中我们已经会用cd进入到指定的目录中.这是导航最常见的用途之一,但是它还有几个值得关注的用途.第一个是使用cd ..(读作'see-dee 点点')返回当前目录级别的上一级: $ pwd / ...
- Android开发——ListView使用技巧总结(一)
)还有一点就是要控制异步任务的执行频率,因为当用户频繁的上下滑动,会瞬间产生上百个异步任务,会带来无意义的大量的UI更新操作,因此可以考虑在列表滑动时停止进行异步任务,直到列表停下来. //判断列表的 ...
- Luogu P3327 [SDOI2015]约数个数和
又是恶心的莫比乌斯反演,蒟蒻我又是一脸懵逼的被CXR dalao狂虐. 题目要求\(ans=\sum_{i=1}^n \sum_{j=1}^m d(ij)\),其中\(d(ij)\)表示数\(x\)的 ...
- Flutter - 退出App
Flutter退出App的方法一般有两种 ①SystemNavigator.pop 推荐 onTap: () async { await pop(); }, static Future<void ...
- C# 根据部分属性来判断俩个对象是否相同
根据部分属性来判断俩个对象是否相同 代码是第一版本 可能不牢固 有问题请反馈一下 3QU 效果图: public static class CustomExpand { public static b ...