\(考虑问题的转换,即把用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. clickhouse客户端使用

    测试初始化 clickhouse-client -m create database if not exists test; use test; drop table test; create tab ...

  2. SpringMVC(3):AJAX

    一,AJAX 简介 AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML) AJAX 不是新的编程语言,而是一种使用现有标准的新方法 ...

  3. WPF 引用第三方库的控件在设计器加上设计时数据和属性

    本文告诉大家如何在 VisualStudio 2022 的 XAML 设计器中,在设计时给第三方控件加上设计用的属性和数据的方法 此功能要求使用不低于 VisualStudio 2019 的 16.8 ...

  4. 【C/C++】指针,传参,引用的一些个人理解。

    (以下均为个人理解) 函数访问的传参两种方式大致为: 值传递: 地址传递. 但是实际上可以都理解为,传进来的[形参]是主函数里的实参值的[一种复制]. 举个例子,哪怕我们将地址作为子函数的输入变量,形 ...

  5. [BUUCTF]PWN——others_shellcode

    others_shellcode 附件 解题步骤: 例行检查,32位程序,开启了NX(堆栈不可执行)和PIE(地址随机化)双重保护 试运行了一下,发现直接就能执行shell的命令 远程连接运行一下,直 ...

  6. CF1036A Function Height 题解

    Content 给定一个坐标系,在它的 \(x\) 轴上有 \(2n+1\) 个点 \(P_0,P_1,P_2,...,P_{2n}\),其中对于 \(0\leqslant i\leqslant 2n ...

  7. LuoguP7911 [CSP-J 2021] 网络连接 题解

    Content 题目过于难解释,请前往题面查看.以下直接给出本题做法. Solution 入门组 T3 在我印象中向来都不是很容易能做出来的题目,但是今年这个 T3 不得不说还是挺好做的. 我们先不妨 ...

  8. AT4151 [ABC099B] Stone Monument 题解

    Content 一个村里有 \(999\) 个房子,第 \(i\) 个房子的高度为 \(1+2+...+i=\sum\limits_{j=1}^ij\).现在下了一场雪,给定相邻两个房子没被雪覆盖的高 ...

  9. 网络编程socket 结合IO多路复用select; epool机制分别实现单线程并发TCP服务器

    select版-TCP服务器 1. select 原理 在多路复用的模型中,比较常用的有select模型和epoll模型.这两个都是系统接口,由操作系统提供.当然,Python的select模块进行了 ...

  10. pymysql-sqlalchemy-orm

    sqlalchemy示例代码 多对多外键 场景:一个作者映射多个书籍,一个书籍有多个作者 作者表: id name email sex 1 Alex alex@.. M 2 Rail rail@.. ...