http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627

http://acm.fzu.edu.cn/problem.php?pid=2238

对应的51NOD这个题,先把n--和没m--

再套公式

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
LL quick_pow(LL a, LL b, LL MOD) { //求解 a^b%MOD的值
LL base = a % MOD;
LL ans = ; //相乘,所以这里是1
while (b) {
if (b & ) {
ans = (ans * base) % MOD; //如果这里是很大的数据,就要用quick_mul
}
base = (base * base) % MOD; //notice。注意这里,每次的base是自己base倍
b >>= ;
}
return ans;
}
LL C(LL n, LL m, LL MOD) {
if (n < m) return ; //防止sb地在循环,在lucas的时候
if (n == m) return ;
LL ans1 = ;
LL ans2 = ;
LL mx = max(n - m, m); //这个也是必要的。能约就约最大的那个
LL mi = n - mx;
for (int i = ; i <= mi; ++i) {
ans1 = ans1 * (mx + i) %MOD;
ans2 = ans2 * i % MOD;
}
return (ans1 * quick_pow(ans2, MOD - , MOD) % MOD); //这里放到最后进行,不然会很慢
}
const int MOD = 1e9 + ;
void work() {
int n, m;
cin >> n >> m;
cout << C(n + m - , n - , MOD) << endl;
}
int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

51NOD

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
LL a, d, m, i;
const int MOD = ;
LL quick_pow (LL a, LL b, LL MOD) {
//求解 a^b%MOD的值
LL base = a % MOD;
LL ans = ; //相乘,所以这里是1
while (b) {
if (b & ) {
ans = (ans * base) % MOD; //如果这里是很大的数据,就要用quick_mul
}
base = (base * base) % MOD; //notice
//注意这里,每次的base是自己base倍
b >>= ;
}
return ans;
}
LL C (LL n, LL m, LL MOD) {
if (n < m) return ; //防止sb地在循环,在lucas的时候
if (n == m) return ;
LL ans1 = ;
LL ans2 = ;
LL mx = max(n - m, m); //这个也是必要的。能约就约最大的那个
LL mi = n - mx;
for (int i = ; i <= mi; ++i) {
ans1 = ans1 * (mx + i) % MOD;
ans2 = ans2 * i % MOD;
}
return (ans1 * quick_pow(ans2, MOD - , MOD) % MOD); //这里放到最后进行,不然会很慢
}
LL Lucas (LL n, LL m, LL MOD) {
LL ans = ;
while (n && m && ans) {
ans = ans * C(n % MOD, m % MOD, MOD) % MOD;
n /= MOD;
m /= MOD;
}
return ans;
} void work () {
if (i == ) {
printf ("%lld\n", a);
return;
}
LL ans = (C(m + i - , m, MOD) * a % MOD + C(m + i - , i - , MOD) * d % MOD) % MOD;
printf ("%lld\n", ans);
return ;
}
int main() {
#ifdef local
freopen("data.txt", "r", stdin);
#endif
while (scanf("%lld%lld%lld%lld", &a, &d, &m, &i) != EOF) work();
return ;
}

FZUOJ

Problem 2238 Daxia & Wzc's problem 1627 瞬间移动的更多相关文章

  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. 【数论】FOJ 2238 Daxia & Wzc's problem

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

  3. 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 ...

  4. FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)

    Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : ...

  5. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem A: The 3n + 1 problem(水题)

    Problem A: The 3n + 1 problem Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 14  Solved: 6[Submit][St ...

  6. 51Nod 1627 瞬间移动 —— 组合数学

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 1627 瞬间移动  基准时间限制:1 秒 空间限制:1 ...

  7. 51 Nod 1627瞬间移动(插板法!)

    1627 瞬间移动  基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右 ...

  8. FZU 2240 Daxia & Suneast's problem

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

  9. FZU Problem 2244 Daxia want to buy house

    模拟题,注意: 1.那两个贷款都是向银行贷的,就是两个贷款的总额不能超过70%,就算公积金贷款能贷也不行,我开始的时候以为公积金贷款是向公司借的,,欺负我这些小白嘛.... 2.最坑的地方 *0.7是 ...

随机推荐

  1. 1250太小了 mysql 并发

    SHOW VARIABLES LIKE '%connection%'; character_set_connection utf8mb4collation_connection utf8mb4_gen ...

  2. Random 类生成随机数

    Random类 (java.util) Random类中实现的随机算法是伪随机,也就是有规则的随机.在进行随机时,随机算法的起源数字称为种子数(seed),在种子数的基础上进行一定的变换,从而产生需要 ...

  3. Delphi通过Get获取来自PHP的返回值

    Delphi代码 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contro ...

  4. atomic_cmpxchg()/Atomic_read()/Atomic_set()/Atomic_add()/Atomic_sub()/atomi

    [ 1.atomic_read与atomic_set函数是原子变量的操作,就是原子读和原子设置的作用.2.原子操作,就是执行操作的时候,其数值不会被其它线程或者中断所影响3.原子操作是linux内核中 ...

  5. UUIDUtils

    package com.cc.hkjc.util; import java.util.UUID; /** * 字符串工具类 *  * @author:匿名 *  */public class UUID ...

  6. web 基本概念辨异 —— URI 与 URL

    两者的相同点: 都是唯一的,对资源(R:Resource)起到唯一的标识作用: 两者的不同点: URL 是 URI 的子集(URI 是父类,URL 是子类),是一种特定的实现形式: URI 可以是身份 ...

  7. 【AHOI2009】中国象棋

    [题目链接] 点击打开链接 [算法] 动态规划 f[i][j][k]表示前i行,有j列放了1个,有k列放了两个 分六种情况讨论即可 [代码] #include<bits/stdc++.h> ...

  8. 【前端】Element-UI 省市县级联选择器 JSON数据

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/element_cascader.html 不想自己处理的就直接下载吧 http://shamoyuu.bj.bce ...

  9. 传统开发有必要学Dubbo吗

    dubbo作为一个知名的分布式服务调用框架,在众多互联网公司都有广泛的应用.但其本质还是一个远程服务调用框架,最初就是为了应对SOA服务治理时才用到的,如果本身服务不多就没必要用它了.如果对技术感兴趣 ...

  10. laravel5.2数据库基本操作

    laravel5.2数据库基本操作 百牛信息技术bainiu.ltd整理发布于博客园 use Illuminate\Database\Eloquent\Model; use Illuminate\Da ...