光速幂

从航模到工具:用固定翼无人机完成一次标准的测绘任务,我的全流程记录(含设备清单与参数设置) 本文详细记录了使用固定翼无人机完成标准测绘任务的全流程,包括设备选型、改装方案、任务规划、飞控调校及实战操作。重点介绍了Skywalker X8机身、Pixhawk 4飞控等关键设备的选择与配置,以及航线设计、气象评估等实用技巧,为航测爱好者提供了一套完整的低成本高效解决方案。 阅读详情
AI摘要

本文深入探讨了光速幂算法,一种在特定条件下优于快速幂的幂运算算法。通过预处理,光速幂能实现O(1)的时间复杂度进行模幂运算,尤其适用于大量询问的场景。文章详细解释了算法原理,包括欧拉定理的应用,以及如何通过优化预处理达到最佳性能。

warning:如果你还没有学过快速幂,请掉头先学快速幂因为快速幂的适用范围比这个东西更广

我们先回忆一下快速幂是怎么解决的
我们是利用二进制的性质将复杂度优化到单词询问O(log⁡index)O(\log index)O(logindex)
但是在有些题目中,可能复杂度不支持我们再在原有复杂度上增加一个log⁡\loglog(比如询问变成10710^7107次)
那么这个时候就需要运用到光速幂的内容了

当我们计算ab mod pa^b \bmod pabmodp的时候,我们可以令b=ks+tb=ks+tb=ks+t,其中s,ts,ts,t是常数,t≤st\leq st≤s
那么我们只需要预处理出任意一个a0,a1,a2...asa^0,a^1,a^2...a^sa0,a1,a2...as,a0,as,a2s,a3s...a⌈ps⌉sa^0,a^s,a^{2s},a^{3s}...a^{\lceil\frac{p}{s}\rceil s}a0,as,a2s,a3s...a⌈sp​⌉s,那么最后询问答案就是aks×bta^{ks}\times b^taks×bt就可以O(1)O(1)O(1)得到答案
那为什么我们的预处理的上界要取到ppp呢?其实应该上界是ϕ(p)\phi(p)ϕ(p),但是为了方便我们就算到ppp。
根据欧拉定理
aϕ(p)≡1  mod pab≡ab mod ϕ(p)  mod p \begin{aligned} a^{\phi(p)}&\equiv 1\ &\bmod p \\ a^{b}&\equiv a^{b \bmod \phi(p)}\ &\bmod p \end{aligned} aϕ(p)ab​≡1 ≡abmodϕ(p) ​modpmodp​
也就是说,对于任意的aba^bab,一定有一个ac(c≤ϕ(p))a^c(c\leq\phi(p))ac(c≤ϕ(p))和他模ppp同余

那么显然当sss取⌈p⌉\lceil\sqrt p\rceil⌈p​⌉时可以做到不漏的情况下复杂度最优

那么我们直接处理出这些幂就可以了

下面给出的是洛谷模板题代码,记得指数要 mod  ϕ(p)\bmod\ \phi(p)mod ϕ(p)

#include <bits/stdc++.h>
using namespace std;

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int a,b,p,bl;
int poww[N][2];

int phi(int x){
    int res=x;
    for(int i=2;i*i<=x;i++){
        if(x%i==0)res=res/i*(i-1);
        while(x%i==0)x/=i;
    }
    if(x>1)res=res/x*(x-1);
    return res;
}

int Qpow(int ind){
    ind%=phi(p);
    return 1ll*poww[ind%bl][0]*poww[ind/bl][1]%p;
}

signed main()
{
    read(a),read(b),read(p);
    bl=sqrt(p)+1;
    poww[0][0]=1;
    Rep(i,1,bl)poww[i][0]=1ll*poww[i-1][0]*a%p;
    poww[0][1]=1;
    Rep(i,1,bl)poww[i][1]=1ll*poww[i-1][1]*poww[bl][0]%p;
    printf("%d^%d mod %d=%d\n",a,b,p,Qpow(b));
    return 0;
}

下面简单的分析一下光速幂和快速幂的优点缺点

性能快速幂光速幂
时间复杂度单次询问O(log⁡b)O(\log b)O(logb)预处理O(p)O(\sqrt p)O(p​),询问O(1)O(1)O(1)
空间复杂度$$
应用范围任何时候都可以使用只有在底数相同,模数相同时可以使用
码量短比快速幂稍长(如果写ϕ\phiϕ的话)
​​​​手把手教你玩转RT-Thread操作系统专栏--​​​​第5章 设备驱动开发:RT-Thread的设备框架​​​​5.4 I2C/SPI驱动:如何驱动外部传感器(以MPU6050为例)​ 通过本节学习,掌握了基于RT-Thread设备模型的I2C/SPI驱动开发流程,包括硬件初始化、寄存器读写、设备注册及应用程序调用。I2C(Inter-Integrated Circuit)和SPI(Serial Peripheral Interface)是嵌入式系统中最常用的两种串行总线协议,广泛用于连接传感器、存储器等外设。函数通过I2C协议读取外设寄存器的数据(如MPU6050的加速度寄存器)。SPI读取需先拉低片选(CS),发送寄存器地址,再读取数据,最后拉高CS。查找I2C设备,并调用。 阅读详情

相关推荐

别再只会插拔了!深入Linux内核,手把手调试USB热插拔中断(以高通平台为例)

本文深入探讨了Linux内核中USB热插拔中断的调试方法,特别针对高通平台提供了详细的实战指南。从硬件基础到内核机制,再到中断调试工具和常见问题排查,帮助开发者系统性地解决USB设备识别问题。通过监控中断状态、分析处理流程和高级调试技巧,提升USB热插拔的稳定性和性能。

weixin_29161785的博客 428

算法|数学与数论|快速幂和光速幂

数学与数论-快速幂和光速幂

m0_74195832的博客 2728

从原理图到代码:深入解析SX1278 LoRa模块与STM32的SPI通信驱动(附完整工程)

本文深入解析了SX1278 LoRa模块与STM32的SPI通信驱动实现,从硬件原理图到完整工程代码,详细介绍了LoRa技术的通信原理、寄存器配置、SPI接口设计及低功耗优化策略。适合物联网开发者和嵌入式工程师提升远距离无线通信能力,附完整工程代码助力快速开发。

weixin_42715608的博客 423

光速幂板子

光速幂 时间复杂度O(T+sqrt(m))(T是询问次数,m是模数大小) s=sqrt(p) p是模数大小ax≡axs∗s+x%smod p s=sqrt (p)\ p是模数大小\\ a^x\equiv a^{\frac{x}{s}*s+x\%s} mod \ p s=sqrt(p) p是模数大小ax≡asx​∗s+x%smod p #include<bits/stdc++.h> using namespace std; const int mod = 1

qq_46580275的博客 481

openEuler Embedded新增软件包及在线安装软件方法

openEuler Embedded是基于Yocto构建的嵌入式操作系统,默认不包含dnf/apt软件包管理器,主要使用rpm格式。新增软件需通过manifest文件检查是否集成,未集成则需适配新配方。对于在线安装需求,可采用轻量级容器方案:通过isulad运行openEuler服务器版容器镜像,在容器内使用dnf命令安装软件(如Nginx),实现服务器生态兼容。部署前提包括设备支持、存储空间(≥10GB)和网络连接,需先安装并启动isulad服务。这种方法结合了嵌入式系统的轻量化特性和服务器系统的软件管理

专注嵌入式开发与 Linux 系统应用实战,分享芯片驱动、设备调试、系统工具开发干货。 1225

SIMetrix教程-001.SIMetrix软件简介与安装

  由于某些原因需要用到SIMetrix仿真软件,然而网上的资料并不是特别多,故在此记录一下这款仿真软件的学习过程,也给有需要的人提供一些参考,免走弯路。如果使用过Pspice或者LTspice软件,学习SIMetrix会很容易入门,仿真软件都是大同小异的,会一样后都可以快速入门其他软件。   SIMetrix是一款以SPICE模型为基础的仿真软件,集成了SIMetrix和SIMPLIS两款内核,为工程师提供了可靠的、易于使用的、并完美结合了速度与精度的电路仿真方式。官方的话不多说,和LTspice一样,优

gaoyong_wang的博客 2万+

快速幂、光速幂 模板

快速幂:快速求a^b % p的问题,时间复杂度:O(logb),若对于n组数据,那么时间复杂度为O(nlogb) 一.如果用暴力解法 O(nb)会TLE 基本思路:对于 n 组数据,分别循环b次求出a^b mod p 二.快速幂解法 O(nlogb)(n组数据,每组logb,b表示几次幂) 基本思路: 1.预处理出 a(20),a(21),a(22),…,a(2logb) 这b个数 2.将 a^b 用 a(20),a(21),a(22),…,a(2logb) 这b种数来组合,即组合成: ab=a(2^x1

Jacob0824的博客 649

AI使用指南:6个超实用的Prompt提示词模板

最近越来越多人开始接触AI,但其实想要让AI更懂你,关键是掌握对的提示词模板!今天就给大家分享6种超实用的Prompt提示词模板,不管你是小白还是老手都能用

程序员世杰 8166

光速幂 - 加强版快速幂

考虑一个问题:a ^ b % p。 你可能会说,这不是快速幂板子吗? 但是如果询问有1e7组呢? 这时就需要用到光速幂了。 考虑指数b,我们其实可以把b根号分解,然后根号预处理。 模板: #pragma GCC optimize("-Ofast","-funroll-all-loops") #include<bits/stdc++.h> #define int long long u...

青烟绕指柔的博客 1297

LPDDR4x 深度解析(3) - SDRAM核心操作机制

本文深入解析LPDDR4x SDRAM的核心操作机制,包括基础架构、刷新操作、读写流程及低功耗设计。详细介绍了存储阵列、地址解码器等关键模块,以及自刷新与自动刷新模式的区别。通过实测数据和技术细节,揭示LPDDR4x在性能优化和功耗控制方面的创新设计,为硬件工程师提供实用参考。

weixin_29278805的博客 307

人形机器人电路板和算法分析

人形机器人电路板与算法深度剖析 电路板领域:人形机器人电子系统分为计算、驱动、感知、能源、通信五大模块。主控板采用高性能SoM(如NVIDIA Jetson AGX Orin),需满足严格电源完整性(PDN)与信号完整性(SI)要求;关节驱动板集成MCU、GaN/SiC功率器件及高精度编码器接口,采用刚柔结合PCB以适应狭小空间。挑战包括热-振可靠性(85°C/10G振动)、高密度互连(3mil线宽)及EMC兼容性。 算法领域:运动控制依赖MPC(模型预测控制)与强化学习(RL),实现实时动态平衡;感知算法

几十年资深高级架构师,技术专家的技术笔记。专注C、Java、Python、微服务、云原生、AI工程化及高并发系统分布式架构实战,分享源码剖析、性能调优与架构治理经验。 305

LG P3747 [六省联考2017]相逢是问候(欧拉定理+(暴力)线段树+光速幂)

题目 这题怎么出的这么好啊。 发现这个操作很不常规,那么就一定会有一些很不常规的性质。 ci≡cimod&ThinSpace;&ThinSpace;φ(p)(modp)c^i \equiv c^{i\mod \varphi(p)} \pmod pci≡cimodφ(p)(modp) cci≡c(cimod&ThinSpace;&ThinSpace;φ(p))≡cim...

Freopen的博客 390

《FreeRTOS 入门与实战》第20章:移植到 RISC-V 平台

处理器上下文保存/恢复机制中断处理与任务切换的协同时钟源配置(通常使用 Machine Timer)平台特定的汇编代码实现// 典型RISC-V移植文件结构FreeRTOS/├── Source/portable/[编译器]/RISC-V/│ ├── port.c // 关键移植接口│ ├── portASM.s // 汇编级处理│ └── portmacro.h // 架构宏定义。

2301_79143213的博客 448

2019 南昌ICPC网络赛 H题 The Nth Item (二阶线性数列递推+光速幂) or (矩阵快速幂+广义斐波那契循环节)

2019 南昌ICPC网络赛 H题 The Nth Item (二阶线性数列递推+快速幂优化) or (矩阵快速幂+广义斐波那契循环节)题意思路二阶线性数列递推+快速幂优化Code矩阵快速幂+广义斐波那契循环节Code 传送门:https://nanti.jisuanke.com/t/41355 题意 F0=0    F1=1F_0=0\;\;F_1 =1F0​=0F1​=1 Fn=3Fn−1+2Fn−2(n≥2)F_{n}=3F_{n-1}+2F_{n-2}(n\ge 2)Fn​=3Fn−1​+2Fn−2

狙击美佐的博客 298

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

莫队+光速幂+根号枚举:不固定模数区间统计题解

区间统计与离线查询是算法工程中常见的基础问题:给定静态序列和多次区间询问,若统计量与元素出现次数相关,通常需要把询问排序后增量维护计数与加权和。面对每次询问模数不固定、快速幂重复计算代价高的情况,可分块预处理指数幂表,用光速幂把单次幂查询降到常数级;结合出现次数种类至多O(√n)的稀疏性,用栈维护非空次数集合,便能在根号级别完成枚举。该思路兼顾莫队算法的增量转移与根号分治的复杂度控制,适用于竞赛评测、区间频次统计和多模数加权求和等场景。围绕“盼君勿忘”这道题,可看到莫队、光速幂与稀疏枚举如何组成一条完整的优

weixin_31421613的博客 237

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【ybtoj高效进阶 21279】排列计数(矩阵乘法)(光速幂)(DP)

多次询问,每次问你有多少个长为 n 的排列满足相邻两个的差是 2 一下。

欢迎您的光顾awa 318

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

洛谷P5110:块速递推(特征根方程、光速幂)

特征根方程练习

BUG_Creater_jie的博客 487

光速幂学习笔记 & P1226 【模板】快速幂||取余运算

背景: 别跟我说这是快速幂,小心我用底数相同的数据卡你。 题目传送门: https://www.luogu.org/problem/P1226 题意: 求:nkmod&ThinSpace;&ThinSpace;pn^k\mod pnkmodp。 思路: 学习快速幂的请自觉屏蔽。 可能有边界问题,实际以代码为准。 考虑k&gt;⌊n⌋k&gt;\lfloo...

zsyz_ZZY的博客 979

Luogu P5110 块速递推

题目大意 %  对于序列 A={ai∣i∈[0,264]}A=\{a_i|i\in[0,2^{64}]\}A={ai​∣i∈[0,264]},有 a0=0,a1=1,an=233an−1+666an−2a_0=0,a_1=1,a_n=233a_{n-1}+666a_{n-2}a0​=0,a1​=1,an​=233an−1​+666an−2​,共 TTT 个询问,对于每个询问,给定 nnn,输出 a...

linjiayang2016的博客 246

兰州大学第一届『飞马杯』糖果魔法阵(扩展欧拉定理+光速幂+打表找规律)

题目链接:https://ac.nowcoder.com/acm/contest/16520/G 分析 看了pdf题解,感觉上面推的公式太难了太过复杂,可以通过打表的方式找出规律。 对于这个更新糖果数的公式,我们写出它的前几项: 915057325 313715344 828907141 687199838 216660350 397265547 16066133 150000439 661125904 521509362 713551262 678018512 284693091 320225841 7

Sankkl1的博客 377

P5072 [Ynoi2015] 盼君勿忘

出现的次数可以用c[N]计数,出现该次数的数可以用sum[N]记录,有几种k可以用双向链表记录或者set,(选择unordered_set常数比较小)学了一下双向链表,unordered_set, 光速幂感觉比做思维题有收获。假设存在一个x,它在[l,r]区间出现了k次,我们想计算它的贡献。k最多有sqrt(n)个 如果用快速幂预处理的话时间复杂度是。sn是等差求和 k=1,k=2,k=3...理论上来说能过?反向考虑一下,我们知道子字串的数量,没有x的子字串的数量。考虑计算每个数对答案所作的贡献。

Lanthamum的博客 441

HDU 6331 Walking Plan

题意:n个点的图,求s到t经过至少k条边的最短路。 1&lt;=n&lt;=50 , 1&lt;= k &lt;=10000 设恰好经过k条边的最短路为dis[k][i][j] 预处理很容易,但是TLE 发现dis[a+b][i][j] = min(dis[a][i][k] + dis[b][k][j])总是成立 发现预处理时间复杂度过大,处理询问复杂度过小(O(1)) 考虑把复杂度移...

Freopen的博客 268

P3747 [六省联考 2017] 相逢是问候(欧拉定理、线段树、光速幂)

拓展欧拉定理

BUG_Creater_jie的博客 607

The Nth Item

题目链接:https://nanti.jisuanke.com/t/41355 解题思路:其实这道题思路很简单,就是求出每一次的n1带进去算出F(n1),然后n2就是n1xor F(n1)2,关键在于时间限制是1000ms; 本题采用 二次剩余定理+求逆元+光速幂 利用二次剩余定理+求逆元 可以将该方程转化为 f(n)=559329360(262199973n-736044383...

weixin_30344795的博客 211
上一篇: 扩展欧拉定理
下一篇: [六省联考2017]相逢是问候
NephrenRuqInsania
博客等级 码龄8年 20粉丝 115原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值