LightOJ1067 Combinations[Lucas]

SecureCRT串口连接保姆级教程:从驱动安装到波特率设置(附常见问题解决) 本文提供SecureCRT串口连接的保姆级教程,涵盖从USB转串口驱动安装、端口识别到波特率等核心参数设置的完整流程。针对连接失败、乱码、键盘输入无响应等高频问题,给出了深度排查与解决方案,帮助网络与嵌入式开发新手快速掌握串口调试技能。 阅读详情


A -  Combinations
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Given n different objects, you want to take k of them. How many ways to can do it?

For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways.

Take 1, 2

Take 1, 3

Take 1, 4

Take 2, 3

Take 2, 4

Take 3, 4

Input

Input starts with an integer T (≤ 2000), denoting the number of test cases.

Each test case contains two integers n (1 ≤ n ≤ 106), k (0 ≤ k ≤ n).

Output

For each case, output the case number and the desired value. Since the result can be very large, you have to print the result modulo  1000003 .

Sample Input

     

3

4 2

5 0

6 4

Sample Output

     

Case 1: 6

Case 2: 1

Case 3: 15



题意:

算组合数C(k,n)


第一次接触数论的题目

应该算是一个lucas的模版题

里面用到了逆元  用费马小定理算的    n的关于mod逆元等于n的mod-2次方


先阶乘打表   然后求出逆元


lucas:




#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
using namespace std;
const long long mod=1e6+3;
long long nc[mod];
void initial()//n!
{
    nc[0]=1;
    for (int i=1 ; i<mod ; i++)
        nc[i]=(nc[i-1]*i)%mod;
}
long long pow(long long n,long long m)//快速幂
{
    n%=mod;
    long long res=1;
    while (m)
    {
        if(m&1)
            res=res*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return res;
}
long long C(long long n,long long k,long long m)
{
    return nc[n]*pow(nc[k]*nc[n-k],m-2)%m;//    n^(mod-2) 是n的逆元
}
long long lucas(long long n,long long k,long long m)//lucas 递归版
{
    if (!k || !n)
        return 1;
    return lucas(n/m,k/m,m)*C(n%m,k%m,m)%m;
}
int main()
{
    initial();
    int T;
    long long n,k;
    scanf("%d",&T);
    for (int test=1 ; test<=T ; test++)
    {
        scanf("%lld%lld",&n,&k);
        printf("Case %d: %lld\n",test,lucas(n,k,mod));
    }
    return 0;
}




SSE 传输过程中,丢失空格和回车符,怎么解决? Server - Sent Events(SSE)即服务器发送事件,是 HTML5 中的一项 Web API,用于实现服务器向客户端浏览器推送实时数据的功能。 阅读详情

相关推荐

SuccessFactors入门篇

SuccessFactors入门篇—— Employee Central(一)最近通过一个月左右的学习,拿到了SF EC(SuccessFactors Employee Central )模块SAP认证,所以打算把自己学习SF的整个过程以及相关资料和大家分享一下,相互切磋,共同进步。Employee Central简单了解Employee Central简单了解新的改变功能快捷键合理的创建标题,有...

qq_42288853的博客 1万+

LightOJ 1067 - Combinations (Lucas定理)

1067 - Combinations   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Given n different objects, you want to take kof t

滴水穿石,慢慢积累,总会有成果 666

Codesys电子凸轮Cam表实战:从可视化配置到程序化构建

本文详细介绍了Codesys电子凸轮Cam表的实战应用,从可视化配置到程序化构建的全过程。通过包装机和印刷机案例,解析Cam表的基础设置、调试技巧及动态构建方法,帮助工程师快速掌握电子凸轮技术,提升运动控制精度和效率。

weixin_29309785的博客 308

【LightOJ】1067 - Combinations(Lucas & 逆元)

点击打开题目 1067 - Combinations   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Given n different objects, you want to

wyg1997 653

Spine动画在Unity里卡顿、闪烁、排序错乱?这些性能优化与渲染问题一次讲清

本文深入解析了Spine动画在Unity中常见的卡顿、闪烁和排序错乱问题,提供了全面的性能优化与渲染解决方案。从性能瓶颈诊断到材质合并、动态合批优化,再到层级错乱与Alpha闪烁的处理,帮助开发者提升动画表现和运行效率。特别针对Unity和Spine的协同工作进行了详细的技术探讨。

weixin_29967445的博客 390

ONVIF协议简介与协议测试工具使用详解

Onvif协议及协议测试工具使用详解

dvlinker的技术专栏 3万+

LightOJ1067 Combinations Lucas定理裸题

Description Given n different objects, you want to take k of them. How many ways to can do it? For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways. Take 1, 2 T

Megumin的博客 815

【ROS2】机械臂MoveIt2

navigation2 专注于移动机器人的导航与定位,处理大范围空间的底盘运动;MoveIt2 专注于机械臂的操作规划,处理多关节协同的末端执行器运动。在复合机器人(如,移动机械臂)navigation2 负责移动到目标区域,MoveIt2 负责机械臂抓取。官网:https://moveit.picknik.ai/main/index.html。

郭老二 622

LightOJ 1067 - Combinations【Lucas定理】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1067题意: 组合数求模,Lucas定理代码:#include <stdio.h> #include <math.h> #include <stdlib.h> #include <algorithm> #include <string.h> #include

mfcheer 702

ADBC 全面解析:ABAP 开发者玩转 Native SQL 的实战指南

本文介绍了 SAP ABAP 中的 ADBC(ABAP Database Connectivity)技术,它是一种基于 ABAP 面向对象的类库,用于访问 Native SQL 接口。与 Open SQL 和 EXEC SQL 相比,ADBC 具有以下优势:支持特定数据库语法、可访问二级数据库连接、执行多种 SQL 操作且语法更 ABAP 化。文章通过示例展示了 ADBC 的基本用法,包括创建语句对象、执行查询和处理结果集。建议在需要数据库特有功能或二级连接时优先使用 ADBC,同时提供封装类来简化调用。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 326

关于cefsharp访问iqiyi.com显示403 Forbidden解决办法(2种方法)

cefsharp不加UserAgent的默认值为 (注意126是当前cefsharp的版本)Edge浏览器的UserAgent 为 (edge的版本是128的)说明根据浏览器的不同,UserAgent可能不太一样。

无线智能模块 可视DIY智能专家 1415

Lightoj 题目1067 Combinations(lucas)

C - Combinations Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1067 Description Given n different objects, you want to take k 

Jogging_Clown 541

库存优化技术提升电商效率

第一部分:库存优化技术基础 第1章:库存优化的基本概念 库存优化是现代电商运营中至关重要的一个环节。简单来说,库存优化指的是通过一系列的策略和技术手段,使得库存管理更加高效、准确,从而降低运营成本,提高销售额。 1.1 库存优化的定义与重要性

AI天才研究院 1252

LightOJ1067 Combinations( Lucas定理或者技巧)

Givenndifferent objects, you want to takekof them. How many ways to can do it? For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways. Take 1, 2 Take 1, 3 Tak...

qq_43642142的博客 163

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Combinations LightOJ - 1067

题目:CombinationsLightOJ - 1067 题意:有n个数,你从中拿走k个,一共有多少种可能。 思路:这道题从题意中很明显的看出这道题是组合数学,但是数据比较大,你不能把所有的结果都求出来再模上一个数,这显然是不可能的,所以需要你换一种思路,所以想到Lucas定理。通过Lucas来求解,该题。 代码: 本题用到了递归求逆元:逆元的求法总结(3种基本方法+4种实现) ...

REfusing的博客 245

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

LightOJ - 1067 Combinations

Combinations  Given n different objects, you want to take k of them. How many ways to can do it? For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways. Take 1,

Eiffel的博客 579

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

lightOJ 1067 - Combinations

纯粹的lucas定理,因为n,m的数据比较小,所以可以直接用公式: c(n,m) = ( (a! * ((a-b)!)^(p-2) % mod) * ((b!)^(p-2)) ) % mod; 详见代码:#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <list> #inc

onehrxn的博客 468

lightoj 1067 - Combinations

1067 - Combinations     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Given n different objects, you want to take k of them. How m

z2664836046的博客 373

lightoj 1067 - Combinations 组合数取模

题意:求组合数C(n,k)%mod,mod=1e6+3; 题解:看别人都是lucas定理来解的,怎么看怎么不会用到这题上。。我自己暴力了。用sum[i]记录1*2*...*i%mod。pows[i]记录pow_mod(1,mod-2)*...*pow_mod(i,mod-2)。pow_mod(b,mod-2)为b的逆元,可用费马定理来证明。从而得出a/b%mod=a*b^(mod-2)%mod。

冷月之殇 1378

LightOJ 1067 Combinations 组合数取模

题意是求C(n,m) % (1e6 + 3) 我看别人都是用lucas定理解的,我是暴力求解的,打0-n的逆元表,然后直接算

u013572211的专栏 572

LightOJ 1067 Combinations(费马小定理+逆元)

M - Combinations Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld &amp; %llu Description Given n different objects, you want to take k of them. How many ways to can do it? For e...

辞树 518

1067 - Combinations (费马小定理求逆元,卢卡斯定理 大组合数取模)

Given n different objects, you want to take kof them. How many ways to can do it?For example, say there are 4 items; you want to take 2 ofthem. So, you can do it 6 ways.Take 1, 2Take 1, 3Take 1, 4Take...

海绵的博客 300

线性筛 [约数个数/约数和]

刚才手动推了一下 用线性筛筛约数个数和约数和,就顺便写篇博客记录一下。不过网上应该也有不少人推过了。

ControlBear的博客 1万+

SGU106 The equation[扩展欧几里德算法]

A - The equation Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Submit Status Description There is an equation ax + by + c = 0. Given a,b,c,x1,x2,

ControlBear的博客 1432

HDU5768 Lucky7[中国剩余定理+容斥定理]

E - Lucky7 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description When ?? was born, seven crows flew in and stopped beside him. In its c

ControlBear的博客 1329

HDU5663 Hillan and the girl[莫比乌斯反演]

U - Hillan and the girl  HDU - 5663 题意: 给T组数据,每组数据有一个n和一个m,求,其中 题解: 我们反过来,先求出 gcd(i,j) 是平方数的组合个数,因为感觉这个更好算,然后用 n*m 减去这些个数就是答案了。 设 f(x) 为 gcd(i,j)=x 的个数 F(x)

ControlBear的博客 922
上一篇: POJ2481 Cows[树状数组+离散化]
下一篇: POJ3494 Largest Submatrix of All 1’s[单调栈]
ControlBear
博客等级 码龄11年 34粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址