fzu 2238 Daxia & Wzc's problem
来源:互联网 发布:mac book pro 2015 编辑:程序博客网 时间:2024/05/19 01:10
Problem 2238 Daxia & Wzc's problem
Accept: 38 Submit: 136
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题:
Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d;
首先让Daxia求出数列A(0)前n项和,得到新数列A(1);
然后让Daxia求出数列A(1)前n项和,得到新数列A(2);
接着让Daxia求出数列A(2)前n项和,得到新数列A(3);
...
最后让Daxia求出数列A(m-1)前n项和,得到新数列A(m);
Input
测试包含多组数据,每组一行,包含四个正整数a(0<=a<=100),d(0<d<=100),m(0<m<=1000),i(1<=i<=1000000000).
Output
每组数据输出一行整数,数列A(m)的第i项mod1000000007的值.
Sample Input
1 1 3 4
Sample Output
35
Hint
A(0): 1 2 3 4
A(1): 1 3 6 10
A(2): 1 4 10 20
A(3): 1 5 15 35
So the 4th of A(3) is 35.
思路:这题可以的得出一个公式c(m+i-1,i-1)*a+c(m-1-i,i-2)*d。
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;typedef long long LL;const int MOD=1000000007;LL poww(LL a,LL b,LL p){ LL res=1; while(b) { if(b&1)res=(res*a)%p; a=(a*a)%p; b>>=1; } return res;}LL comb(LL a,LL b,LL p){ if(a<b)return 0; if(a==b)return 1; if(b>a-b)b=a-b; LL ans=1,ca=1,cb=1; for(LL i=0;i<b;++i) { ca=(ca*(a-i))%p; cb=(cb*(b-i))%p; } ans=(ca*poww(cb,p-2,p))%p; return ans;}LL Lucas(int n,int m,int p){ LL ans=1; while(n&&m&&ans) { ans=(ans*comb(n%p,m%p,p))%p; n/=p; m/=p; } return ans;}int main(){ int a,d,m,i; while(~scanf("%d%d%d%d",&a,&d,&m,&i)) { LL ans1=Lucas(m+i-1,i-1,MOD)*a%MOD; LL ans2=Lucas(m+i-1,i-2,MOD)*d%MOD; LL ans=(ans1+ans2)%MOD; cout<<ans<<endl; } return 0;}
阅读全文
0 0
- FZU 2238Daxia & Wzc's problem
- fzu 2238 Daxia & Wzc's problem
- fzu 2238 Daxia & Wzc's problem
- FZU 2238 Daxia & Wzc's problem【规律+lucas】
- 【数论】FOJ 2238 Daxia & Wzc's problem
- FZU Problem 2238 Daxia & Wzc's problem(Lucas定理求组合数)
- FZU-2239 Daxia & Yayamao's problem(斜率优化)
- FZU 2239 Daxia & Yayamao's problem 斜率优化
- FOJ有奖月赛-2016年8月 Problem A Daxia & Wzc's problem(找规律)
- FZU Problem 2240 Daxia & Suneast's problem(博弈+[单点更新,区间查询]线段树)
- FZU Problem 2243 Daxia like uber(最短路)
- FZU 2243 Daxia like uber
- fzu 2243 Daxia like uber
- fzu - 2164 Jason's problem
- FOJ 有奖月赛 2016-8 C Problem C Daxia & Suneast's problem
- FZU 2242 Daxia like acute triangle
- fzu 2244 Daxia want to buy house
- FZU 1150 Farmer Bill's Problem
- 1082字符串
- synchronize关键字互斥
- Nginx指定用户
- 第十周
- ajax,json学习笔记(四)跨域
- fzu 2238 Daxia & Wzc's problem
- 1095求和问题
- Android实现密码隐藏显示
- xgboost 相比GBDT有什么区别
- 线性回归
- HBase 部分表无法写入数据的异常处理
- easyui 如何同时左右显示两个datagrid
- 21. Python脚本学习笔记二十一图形化界面
- 一些测试错题