快速幂+等比数列前n项求和并取模+求逆元

YOLO26 实战全流程:从数据集标注到端到端无NMS推理(完整版,附ProgLoss核心调参技巧+避坑指南) 本章节是实战经验的精华❌ 数据集标注不规范,导致模型精度低 → ✅ 严格遵守工业级标注规范,标注框紧贴目标边缘,不要漏标/多标;❌ 训练时未使用预训练权重,导致收敛极慢 → ✅ 必须开启,预训练权重能让模型快速收敛;❌ ProgLoss参数调整幅度过大,导致训练崩溃 → ✅ 每次只调整一个参数,幅度±0.02即可,循序渐进;❌ 推理时强行添加NMS参数,画蛇添足 → ✅ YOLO26无需NMS,推理命令中不要加conf/iou参数,否则会降低推理速度; 阅读详情

题目链接:https://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1242&pid=4

解法:题中给是求一个等比数列的前n项和取模(1e9+7),已知等比数列前n项求和公式为\(s=\frac{a_1(q^n-1)}{q-1}\),现在求前n+1项即可,q==1的时候特判断。但是比较麻烦的是需要取模,也就是我们要求的结果实际是\(s=\frac{q^{n+1}-1}{q-1}\ mod\ (1e9 + 7)\),注意我们求\(q^{n+1} - 1\)时是使用的快速幂算法,已经取过模了,如果与\(q-1\)相除再求模结果会错,所以我们要把\(\frac{x}{y}\ mod\ p\)的形式改为等价的\(x*z\ mod\ p\)的形式。

替换的方法:(参考于http://blog.youkuaiyun.com/mengxiang000000/article/details/53468865)

逆元的定义:若有\(A*x\equiv 1(mod\ y)\)其中A是最小满足这个式子的数,则A就是x对y的逆元。
如果有:
\(s = \frac{x}{y} \ mod\ p\),那么我们就可已寻找y对p的逆元,使得出发变成乘法;若此时设定z为y的逆元,则有\(s\equiv \frac{x}{y} * (y*z) \ mod\ p\),即\(s\equiv x*y\ mod\ p\)

参考代码:

注意是参考代码,不一定可以AC,应该会有一些细节有问题

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long LL;

const LL MOD = 1000000007;

LL mod_pow(LL x, LL n){
    LL res = 1;
    while (n > 0){
        if (n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

LL exgcd(LL m, LL n, LL &x, LL &y){
    LL x1, y1, x0, y0;
    x0 = 1; y0 = 0;
    x1 = 0; y1 = 1;
    LL r = (m % n + n) % n;
    LL q = (m - r) / n;
    x = 0; y = 1;
    while(r){
        x = x0 - q * x1; y = y0 - q * y1; x0 = x1 ;y0 = y1;
        x1 = x; y1 = y;
        m = n; n = r; r = m % n;
        q = (m - r) / n;
    }
    return n;
}

LL cal(LL a, LL m){
    LL x, y;
    LL gcd = exgcd(a, m, x, y);
    m = m < 0 ? -m : m;
    x = (x % m + m) % m;
    return x;
}

int main(){
    LL cs = 0;
    LL k, n;
    while (~scanf("%lld%lld", &k, &n)){
        if (k == 1){
            printf("Case %lld: %lld\n", ++cs, (n + 1) % MOD);
        }
        else{
            //求逆元
            LL z = cal(k - 1, MOD);
            //注意这里求x的方式,没有直接用q^(n+1)-1
            LL x = mod_pow(k, n + 1);
            if (x == 0){
                x = MOD - 1;
            }
            else{
                x = x - 1;
            }
            LL res = x * z % MOD;
            printf("Case %lld: %lld\n", ++cs, res);
        }
    }
    return 0;
}
【零基础入门unity游戏开发——unity3D篇】unity CharacterController 3D角色控制器最详细的使用介绍,并实现俯视角、第三人称角色控制(附项目源码) 【unity小技巧】unity最完美的CharacterController 3d角色控制器,实现移动、跳跃、下蹲、奔跑、上下坡、物理碰撞效果,复制粘贴即用但是我发现很多人还是不理解,都跑来私信问我,所以决定重新做一个更加详细且简单控制器,主要是实现俯视角和第三人称角色控制。添加一个胶囊体,添加Character Controller组件,记得删除Capsule Collider组件,因为Character Controller自带了碰撞,所以不需要Character Controller参数介绍。 阅读详情

相关推荐

SimpleFOC STM32实战:基于F103与HAL库,剖析速度环与电流环的协同控制

本文详细介绍了基于STM32F103与HAL库的SimpleFOC实战应用,重点剖析速度闭环控制与电流环的协同工作原理。通过开发环境搭建、参数调试技巧及性能优化方案,帮助开发者高效实现无刷电机精准控制,适用于机器人、无人机等高精度应用场景。

weixin_29170327的博客 477

[算法题]等比数列快速求和取模

令sum(p,k)=p0+p1+...+pk% sum(p,k) = p^{0} + p^{1} + ... + p^{k}sum(p,k)=p0+p1+...+pk 如何快速求出它的值? 首先当 k% kk 为奇数时,我们可以将指数划分为两部分(因为有0次方,指数的个数为偶数个),如下所示: sum(p,k)% sum(p,k)sum(p,k) =p0+p1+...+pk% = p^{0} + p^{1} + ... + p^{k}=p0+p1+...+pk =(p0+p1+...+pk/2)+(pk/2

qq_20016169的博客 1237

Android音频学习(八)——AudioFlinger线程

在 PlaybackThread 的实现中,Flag 用于标识线程的特殊行为或配置。

miemie2014的博客 1399

等比数列二分求和取模

Sn= a+a2+...+an 要求 Sn mod p 如果用公式算,可能溢出,因此用二分法求 1) 若 n是偶数 Sn= a+...+ a^(n/2) +  a^(n/2+1) +  a^(n/2+2) +...+  a^(n/2+n/2) =(a+...+ a^(n/2)) +  a^(n/2)*(a+...+ a^(n/2)) =Sn/2+ a^(n/2)Sn/2 =(1+ a

BRCOCOLI的博客 1043

电信天翼云OS(ctyunos)内网离线安装Docker-CE保姆级避坑指南(附完整依赖包清单)

本文提供电信天翼云OS(ctyunos)内网环境下Docker-CE的离线安装全攻略,涵盖依赖分析、离线包制备、冲突解决等关键步骤。针对金融、政务等隔离网络场景,详细解析如何通过本地仓库构建和优化配置,实现高效安全的容器化部署,助力企业快速搭建内网Docker环境。

398

Redis中什么是Big Key(大key)问题?如何解决Big Key问题?

通俗易懂的讲,Big Key就是某个key对应的value很大,占用的redis空间很大,本质上是大value问题。key往往是程序可以自行设置的,value往往不受程序控制,因此可能导致value很大。redis中这些Big Key对应的value值很大,在序列化/反序列化过程中花费的时间很大,因此当我们操作Big Key时,通常比较耗时,这就可能导致redis发生阻塞,从而降低redis性能。用几个实际的例子对大Key的特征进行描述:● 一个String类型的Key,它的值为5MB(数据过大); ● 一

weixiaohuai的博客 3万+

等比数列求和取余

一、二分+快速幂 #include<bits/stdc++.h> #define lom long long using namespace std; lom quick(lom a,lom b,lom c)//quick mod { lom ans=1; a%=c; while(b) { if(b&1) ans=ans*a%c; a=a*a%c;...

卑鄙的我 1968

ROS2+PYTHON VENV虚拟环境配置方法

ROS2+PYTHON VENV配置方法本篇针对的是python。

下雨夏云的博客 557

等比数列求和 再取余

2019河北省大学生程序设计竞赛 Icebound and Sequence 分析: 1、等比数列求和 mod p 因为不能保证 p 是素数,所以不能对(q-1)求逆元 .. 法一终..(待补) 2、用二分方法,递归搜索,举个栗子: 当项数 n 为偶数: = = 其中 mid =(1+n) / 2; 当项数 n 为奇数: = = ...

嵩韵儿 478

GitHub 国内加速完全指南(最新):镜像、代理与优化技巧

在国内使用 GitHub 时,经常遇到 clone 慢、打开仓库卡、GitHub Actions 不稳定 等问题。下面是整理好的 GitHub 国内镜像和加速方法大全,高效使用 GitHub。

moton2017的博客 1万+

〔重庆理工大学〕大学物理实验--变温霍耳效应及其参数测定

每个老师要求不同,实验报告内容和数据仅供参考。

Pretty Boy Fox的博客 3044

等比数列求和 (快速幂 + 逆元)

求一个等比数例之和, 并让他对一个数取模。 用到等比数列求和公式, 快速幂, 逆元。 不会证明, 下面给出代码。 #include <stdio.h> #include <string.h> #include <math.h> typedef long long ll; ll multi(ll a,ll b,ll m) ...

学习笔记 3603

InVEST模型 | HAbitat quality模块计算生境质量

 本文详细介绍使用InVEST模型中HAbitat quality模块计算生境质量,包含各个参数的含义、所需数据、数据处理以及需要各个参数注意的地方等过程。

地理空间科学的博客 1万+

3的幂的和 (大数取余)

求:3^0 + 3^1 +...+ 3^(N) mod 1000000007 Input 输入一个数N(0 &lt;= N &lt;= 10^9) Output 输出:计算结果 Sample Input 3 Sample Output 40 #include&lt;cstdio&gt; typedef long long ll; int mod = 1000000007; ...

yuebaba的博客 467

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

快速幂求逆元

逆元的定义: 当 a m ≡ 1(mod p), m即为 a 在mod p 意义下的逆元。(需要注意只有a和p互质,a才有关于p的逆元)。 公式推导: a * b % p ≡ a * m % p;(两边同时乘以b,再除以a)。 1 % p ≡ m * b % p(m为满足这个条件的最小的一一个数,我们就将其称之为b的逆元)。 费马小定理: 由费马小定理可知:对于任意的质数 p ,任意a都满足≡ a,化简可得:b* ≡ b。与前面的逆元公式一一对应可得,m ==。 为什么除法要用逆元?...

weixin_52193673的博客 2286

Statistics and Machine Learning Toolbox

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

【POJ 3233】矩阵快速幂+二分求等比数列前N项和

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=20851#overview 开了一套矩阵和高斯消元方面的题。 POJ3233这题给一个矩阵A,然后求(A+A^2+A^3+……+A^k)%m 一看到这个首先想到的是等比数列求和,但是矩阵不能除,所以要考虑另一种方案。 把这个矩阵拆成两个部分,就是(A+A^2+A^3+……+A^(k

Senbonzakura 2376

深度学习工具包 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")

错位相减法:从七层宝塔问题到算法竞赛中的等差乘等比数列求和

数列求和是算法与数学中的基础问题,其中等差数列与等比数列的求和公式是核心知识。当遇到更复杂的“等差数列与等比数列乘积求和”问题时,直接计算的时间复杂度为O(n),在大数据量下效率低下。错位相减法作为一种经典的代数技巧,通过构造、错位、相减的步骤,能将此类求和问题转化为简单的等比数列求和,从而推导出闭合公式,将计算复杂度降至O(1)或O(log n)。这一方法在算法竞赛、数学建模及性能优化中具有重要价值,尤其适用于处理通项为 `n * q^(n-1)` 形式的数列。本文以经典的“七层宝塔红灯问题”为引,深入剖

weixin_34323858的博客 383

3的幂的和 51Nod - 1013(快速幂+等比数列求和+逆元)

3的幂的和51Nod - 1013求:3^0 + 3^1 +...+ 3^(N) mod 1000000007 Input 输入一个数N(0 &lt;= N &lt;= 10^9) Output 输出:计算结果 Sample Input 3Sample Output 40思路:一开始都想到了用等比数列公式再加上一个快速幂取模求结果,但是提交上去就一直wa,后来听说要求逆元,但是还是不明白为什么要求...

codeswarrior的博客 541

sum A^B 等比数列求和(log(k))

题目地址 -> 一个方法,因为mod捕食不是质数。 poj 1845 -> 两个方法都可以 还有一个求逆元的解法参考以前博客 先化等比数列: 设 sum = (1+q+…+qc) 假设 c为奇数, 则可以得到 sum = (1+q+…+q(c/2)+q((c+1)/2)+…+qc) 则为sum = (1+q+…+q(c/2)+q((c+1)/2)*(1+q+…+q(c/2))) sum = (1+q((c+1)/2)) * (1+q+…+q(c/2)) 当 c 为偶数时,同理, sum = (

qq_45604735的博客 789

等比数列和的快速求法

等比数列是一种常用的数列 朴素的求和方法是直接每项相加,不会影响取模,代码也很简单,但是时间复杂度为o(n),难以令人满意 于是我们想到了通项公式 我们知道,等比数列和前n项和公式为(a1-a1*q^n)/(1-q). 而通过二分计算快速幂可以在log(n)的时间计算出q^n的值,(代码如下)。剩下的貌似就是简单的除法了 int pow2( int a, int b ) { ...

weixin_30639719的博客 141

约数之和(两种方法)

也可以直接用等比树列求和公式,乘上逆元 分治: 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 using ll = long long; 7 const int Mod ...

xiaoxiao66668的博客 1430

线性求逆元

#include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn=1e5+5; const int p=1e9+7; ll inv[maxn]; ll ksm(ll a,ll b){ ll ans=1; while(b){ if(b%2) ans=(ans*a)%p; b/=2; a=(a*a)%p; } return ans; }.

weixin_50904510的博客 278

约数之和 (普通快速幂求逆元做法)

假设现在有两个自然数 A 和 B,S 是 AB的所有约数之和。请你求出 Smod9901的值是多少。

qq_73261465的博客 335

【zqsz&&loi 互测 11.6】 T1

原题题目来源:poj 1845 原题传送门 原题求a^b的约数个数,本题作了修改: 题目很明显是求首项为1,公比为m的等比数列的前t项和Solution 1:等比数列通项公式+快速幂最关键的是取模用到逆元 求逆元?exgcd?费马小定理?不行不行,题目中没有说m和t-1互质 qwq get到了dalao的求逆元的通式: 求:(a/b)%m 公式:(a/b)%m=(a%(m

Loi_LXTT 548

1013 3的幂的和(乘法逆元,快速幂)

求:3^0 + 3^1 +…+ 3^(N) mod 1000000007 输入 输入一个数N(0 <= N <= 10^9) 输出 输出:计算结果 输入样例 3 输出样例 40 先用等比数列求和公式,ans = (3^(n+1) - 1)/ 2 然后用费马小定理对2求逆元,跑两次快速幂就行了。 乘法逆元 #include<bits/stdc++.h> using names...

晚安( ̄o ̄) . z Z 448

轻院 2180GJJ的日常之沉迷数学 逆元求除法取余

题目链接:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2180 题目大意:求数列 k0,k1,k2...kn的和,即等比数列的前n项和对1e9+7取余的结果。 解题思路:等比数列前N项和为,因此只要能够取余即可求得结果。利用扩展GCD求q-1关于mod的逆元然后快速幂取模计算即可。 代码: 1 const int in...

weixin_30782331的博客 147
上一篇: codeforces 839 B Game of the Rows
下一篇: POJ 3279 Fliptile(枚举)
LucianoSi
博客等级 码龄12年 1粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值