Problem A Daxia & Wzc's problem

Accept: 42    Submit: 228
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.
Cached at 2016-08-17 19:08:15.

 
草稿纸上手写一下
a1  a1+d  a1+2d  a1+3d...
a1  2a1+d  3a1+3d  4a1+6d...
a1  3a1+d  6a1+4d  10a1+10d...
...
可以发现这个是一个类似杨辉三角的东西,大概就是C(n, m)这样算的。
然后就用Lucas就行了
  1. //#pragma comment(linker, "/STACK:102400000, 102400000")
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <list>
  11. #include <set>
  12. #include <map>
  13. using namespace std;
  14. typedef long long LL;
  15. typedef pair <int, int> P;
  16. const int N = 1e3 + ;
  17. LL mod = 1e9 + ;
  18. LL f[N];
  19.  
  20. LL Pow(LL a , LL n , LL mod) {
  21. LL res = ;
  22. while(n) {
  23. if(n & )
  24. res = res * a % mod;
  25. a = a * a % mod;
  26. n >>= ;
  27. }
  28. return res;
  29. }
  30.  
  31. LL Comb(LL a , LL b , LL mod) {
  32. if(a < b) {
  33. return ;
  34. }
  35. if(a == b) {
  36. return ;
  37. }
  38. LL ca = ;
  39. for(LL i = ; i < b ; i++) {
  40. ca = (a - i) % mod * ca % mod;
  41. }
  42. return (ca * f[b]) % mod;
  43. }
  44.  
  45. LL Lucas(LL n , LL m , LL mod) {
  46. LL ans = ;
  47. while(m && n && ans) {
  48. ans = (ans * Comb(n % mod , m % mod , mod)) % mod;
  49. n /= mod;
  50. m /= mod;
  51. }
  52. return ans;
  53. }
  54.  
  55. int main()
  56. {
  57. f[] = ;
  58. for(LL j = ; j < N; ++j) {
  59. f[j] = j * f[j - ] % mod; //阶乘
  60. }
  61. for(LL j = ; j < N; ++j) {
  62. f[j] = Pow(f[j], mod - , mod); //逆元
  63. }
  64. LL a, b, m, i;
  65. while(cin >> a >> b >> m >> i) {
  66. if(i == ) {
  67. cout << a << endl;
  68. continue;
  69. }
  70. LL x = Lucas(m + i - , m, mod) * a % mod;
  71. LL y = Lucas(m + + i - , m + , mod) * b % mod;
  72. cout << (x + y) % mod << endl;
  73. }
  74. return ;
  75. }

FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)的更多相关文章

  1. FZU Problem 2238 Daxia & Wzc's problem

    Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...

  2. FZU 2238 Daxia & Wzc's problem

    公式. $a×C_{m + i - 1}^m + d×C_{m + i - 1}^{m + 1}$. 推导过程可以看http://blog.csdn.net/queuelovestack/articl ...

  3. 【数论】FOJ 2238 Daxia & Wzc's problem

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类 ...

  4. Problem 2238 Daxia & Wzc's problem 1627 瞬间移动

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...

  5. FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)

    http://acm.fzu.edu.cn/contest/list.php?cid=152 主要是a题, lucas定理, 就这一版能过..  记录一下代码, 另外两个最短路  一个模拟,没什么记录 ...

  6. FZU 11月月赛D题:双向搜索+二分

    /* 双向搜索感觉是个不错的技巧啊 */ 题目大意: 有n的物品(n<=30),平均(两个人得到的物品差不能大于1)分给两个人,每个物品在每个人心目中的价值分别为(vi,wi) 问两人心目中的价 ...

  7. FZU 2240 Daxia & Suneast's problem

    博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...

  8. FZU 2139——久违的月赛之二——————【贪心】

    久违的月赛之二 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  9. FZU 2138——久违的月赛之一——————【贪心】

    久违的月赛之一 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

随机推荐

  1. 搜索浅谈(Elasticsearch和Lucene4分享)

    刚刚过去的双11,真是给线下运营商好好上了一课.当今的互联网真是炙手可热,大家对互联网的热情是如此之高.相信电商之间的竞争将更加的激烈和残酷,不过,搜索,作为用户体验很重要的一点,各大电商也做的越来越 ...

  2. oraclede chuangjian yu dajian(zhuan)

    http://wenku.baidu.com/link?url=pIKLZJ4sAurjNGjwgChqjRMhCXfn77qy1K_EW3nlGn4eN4roDN8mhSG0GakYbrTBcsD4 ...

  3. 多线程-NSOperation中使用ASIHttpRequest注意事项

    最近做的iPhone项目中有一如下功能: app在用户许可后将本地Photos的照片上传到服务器,期间用户可以做其他任何操作,等上传成功后弹出一个toast通知用户. 原先的代码结构是: 获取照片的操 ...

  4. notepad 行替换使用指南

    notepad++是开源的文本处理软件,性能堪比ultraedit,不过在转用notepad++之后一直为他的行替换功能纠结,UE当中只需要用 [^p] 就可以表示一行,但是在notepad++当中, ...

  5. Hadoop Hive基础sql语法

     目录 Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构 化的数据文件映射为一张数据库表,并提供完整的 ...

  6. Bootstrap初级用户谈谈网页在手机上的显示效果优化

    本人之前已经使用Bootstrap有一段时间了,但是之前做出的网站都只是在电脑端使用,没有注意过手机端的显示效果.这两天自己使用Bootstrap做了一个简单的Web个人日志系统,想在手机端也使用,桌 ...

  7. PHP Framework安装

    Framework 1> 初始化 前提:服务器上已经装有 Apache/Nginx 和 MySQL 进入 hush-framework/hush-app/bin 目录(Linux 下需执行 ch ...

  8. Android 获取assets的绝对路径

    第一种方法:       String path = "file:///android_asset/文件名"; 第二种方法:    InputStream abpath = get ...

  9. delphi TeeChart保存3种图片文件

    var vForm: Tfrm_ChemaShowMainChild;begin vForm := GetActiveForm; vForm.cht_Edit.SaveToMetafile('C:\1 ...

  10. bjfu1281

    思路挺简单的,但因为需要处理大数,所以就比较耗代码了. /* * Author : ben */ #include <cstdio> #include <cstdlib> #i ...