\(考虑问题的转换,即把用n个球,分为r-l+2个部分,其中第1部分表示该区域的球值为l,第二部分表示该区域的球值为l+1\)

\(......第r-l+2部分为不选该区域的球\)

\(该问题等价于在n+1个空中插r-l+1块板,其中一个空可以插多个也可以不插\)

\(方案数即为\binom{r-l+n+1}{n}\)

\(但长度为1-n,因此要减去所有板都在1的情况,即为\binom{r-l+n+1}{n}-1\)

\(当然,n,r,l很大,因此要用Lucas定理\)

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1100050;
const int MOD=1e6+3;
int cnt;
long long Pow(int a, int b, int p) {
long long ans = 1;
long long base = a;
base %= p; while (b) {
if (b & 1) {
ans *= base;
ans %= p;
} base *= base;
base %= p;
b >>= 1;
} return ans;
}
long long inv(int a, int p) {
return Pow(a, p - 2, p);
}
long long fac[MAXN], inv_fac[MAXN];
long long C(long long n, long long m) {
if (m < 0) {
return 0;
}
if (n < m) {
return 0;
}
if (m == 0||n==m)
return 1; long long k = fac[n];
long long ans = k * inv(fac[n - m],MOD);
ans %= MOD;
ans = ans * inv(fac[m],MOD);
ans %= MOD;
return ans;
}
long long Lucas(int n,int m)
{
if(!m)
{
return 1;
}
return C(n%MOD,m%MOD)*Lucas(n/MOD,m/MOD)%MOD;
}
int t;
long long n,l,r; signed main() {
fac[0] = 1;
for (int i = 1; i <= MOD-1; i++) {
fac[i] = fac[i - 1] * i;
fac[i] %= MOD;
}
scanf("%lld",&t);
while(t--)
{
scanf("%lld %lld %lld",&n,&l,&r);
printf("%lld\n",(Lucas(r-l+n+1,n)-1+MOD)%MOD);
}
}

Count Sequences的更多相关文章

  1. 算法 - 求和为n的连续正整数序列(C++)

    //************************************************************************************************** ...

  2. CRT/LCD/VGA Information and Timing

    彩色阴极射线管的剖面图: 1. 电子QIANG Three Electron guns (for red, green, and blue phosphor dots)2. 电子束 Electron ...

  3. CRT/LCD/VGA Information and Timing【转】

    转自:http://www.cnblogs.com/shangdawei/p/4760933.html 彩色阴极射线管的剖面图: 1. 电子QIANG Three Electron guns (for ...

  4. Linux command line exercises for NGS data processing

    by Umer Zeeshan Ijaz The purpose of this tutorial is to introduce students to the frequently used to ...

  5. nodejs api 中文文档

    文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...

  6. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  7. Python数据类型之“序列概述与基本序列类型(Basic Sequences)”

    序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ...

  8. 【leetcode】Repeated DNA Sequences(middle)★

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  9. Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合

    题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...

随机推荐

  1. jstl中的choose标签

    <%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ ta ...

  2. Springboot 入门及Demo

    一:SpringBoot入门1.1:SpringBoot简介Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的 ...

  3. 你的Redis怎么持久化的

    一.持久化套路 OK,一般我们在生产上采用的持久化策略为 (1)master关闭持久化 (2)slave开RDB即可,必要的时候AOF和RDB都开启 该策略能够适应绝大部分场景,绝大部分集群架构. 为 ...

  4. 按照eslint的规则格式化代码

    1.下载eslint. 2.首选项->设置,然后搜索eslint,点击在setting.json中设置.设置内容如下: "editor.codeActionsOnSave": ...

  5. 发布iOS应用(xcode5)到App Store(苹果商店) 详细解析

    发布iOS应用(xcode5)到App Store(苹果商店) 详细解析 作者:Memory 发布于:2014-8-8 10:44 Friday IOS 此教程可能不太适合,请移步至最新最全的:201 ...

  6. 选择…Select…(Power Query 之 M 语言)

    选择行: 筛选Table.SelectRows-文本与数值 筛选Table.SelectRows-日期与时间 保留错误行:= Table.SelectRowsWithErrors( 表, {" ...

  7. 『学了就忘』Linux系统管理 — 85、工作管理相关命令

    目录 1.工作管理简介 2.如何把命令放入后台 3.后台管理命令 (1)查看后台的工作 (2)将后台暂停的工作恢复到前台执行 (3)把后台暂停的工作恢复到后台执行 4.后台命令脱离登录终端运行 1.工 ...

  8. RuoYi项目整合Mybatis-Plus 框架

    RuoYi框架默认使用的是Mybatis框架 但是有的习惯使用MP框架,这就很不方便, 不过可以简单进行整合 引入依赖 <dependency> <groupId>com.ba ...

  9. ARTS Week 18

    Algorithm 本周的 LeetCode 题目为 55. 跳跃游戏 给定一个非负整数数组 nums, 你最初位于数组的 第一个下标 .数组中的每个元素代表你在该位置可以跳跃的最大长度.判断你是否能 ...

  10. 【LeetCode】1182. Shortest Distance to Target Color 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+二分查找 日期 题目地址:https://lee ...