推理:

假如当前计算的是x在%p意义下的逆元,设$p=kx+y$,则

$\Large kx+y\equiv 0(mod\ p)$

两边同时乘上$x^{-1}y^{-1}$(这里代表逆元)

则方程变为$\Large k*y^{-1}+x^{-1}\equiv 0(mod\ p)$

化简得$\Large x^{-1}\equiv -k*y^{-1}(mod\ p)$

$\Large x^{-1}\equiv -\biggl\lfloor\frac{p}{x}\biggr\rfloor *(p\ mod\ x)^{-1}(mod\ p)$

结果为

$\Large x^{-1}\equiv (p-\biggl\lfloor\frac{p}{x}\biggr\rfloor )*(p\ mod\ x)^{-1}(mod\ p)$

除了1,p mod x一定小于x,它的逆元已经算过,所以可以线性求出逆元

void Inverse(int p,int a[],int n){//线性求<=n的数%p意义下的逆元
a[]=;
for(int i=;i<=n;i++){
a[i]=1ll*(p-p/i)*a[p%i]%p;
}
}

线性求所有数模p的乘法逆元的更多相关文章

  1. Hdu 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)

    Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...

  2. 【模板】求1~n的整数的乘法逆元

    洛谷3811 先用n!p-2求出n!的乘法逆元 因为有(i-1)!-1=i!-1*i (mod p),于是我们可以O(n)求出i!-1 再用i!-1*(i-1)!=i-1 (mod p)即是答案 #i ...

  3. A. On The Way to Lucky Plaza 概率 乘法逆元

    A. On The Way to Lucky Plaza time limit per test 1.0 s memory limit per test 256 MB input standard i ...

  4. Light OJ 1067 Combinations (乘法逆元)

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

  5. hdu_1452_Happy 2004 (乘法逆元

    Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...

  6. 乘法逆元__C++

    在开始之前我们先介绍3个定理: 1.乘法逆元(在维基百科中也叫倒数,当然是 mod p后的,其实就是倒数不是吗?): 如果ax≡1 (mod p),且gcd(a,p)=1(a与p互质),则称a关于模p ...

  7. 题解报告:hdu 1576 A/B(exgcd、乘法逆元+整数快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n ...

  8. HDU6608-Fansblog(Miller_Rabbin素数判定,威尔逊定理应用,乘法逆元)

    Problem Description Farmer John keeps a website called ‘FansBlog’ .Everyday , there are many people ...

  9. 简记乘法逆元(费马小定理+扩展Euclid)

    乘法逆元 什么是乘法逆元? 若整数 \(b,m\) 互质,并且\(b|a\) ,则存在一个整数\(x\) ,使得 \(\frac{a}{b}\equiv ax\mod m\) . 称\(x\) 是\( ...

随机推荐

  1. <a>标签的SEO优化细节

    <a>标签的SEO优化细节 如果需要在新窗口中打开链接,我们使用的方法是在a上加上taget=“_blank”,但很多人不知道这是不符合w3c的规范的,在使用严格的DOCTYPE(xhtm ...

  2. 使用Python实现不同目录下文件的拷贝

    目标:要实现将一台计算机的共享文件夹中的文件备份到另一台计算机,如果存在同名的文件只要文件的大小和最后修改时间一致,则不拷贝该文件 python版本:Python3.7.1 python脚本: fro ...

  3. WPF基础之Grid面板

    一.显示 Grid的线条,设置ShowGridLiens="True".

  4. OA系统和ERP系统的区别

    一.OA和ERP的区别 1.含义不同: OA指Office Automation,中文简称自动办公系统,帮助企业内部管理沟通的工具,比如新闻公告.内部沟通.考勤.办公.员工请假.审批流程等. ERP指 ...

  5. HashMap数据结构

    2.1 HashMap 2.1.1 HashMap介绍 先看看HashMap类头部的源码: public class HashMap<K,V> extends AbstractMap< ...

  6. springboot在工具类中添加service的方法,显示为空的解决方案

    @Component// 1.将工具类声明为spring组件,这个必须不能忘 public class TestUtils { //2.自动注入 @Autowired private ItemServ ...

  7. 19-11-10-Night

    关于$Miemeng$,它死了. 大家有没有记得我在暑假里曾经写过一个著名模数? const int Mod=998224353; 现在有续集了(捂脸)(改不过题.jpg) const int Mod ...

  8. jeecms 代码生成 Tools

    本文作者: IIsKei 本文链接: http://www.iskei.cn/posts/50510.html 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议 ...

  9. Ubuntu+Ruby+MySQL+Nginx+Redmine部署记录

    (2019年2月19日注:这篇文章原先发在自己github那边的博客,时间是2016年7月26日) 周五的时候老大布置了一个任务下来,要部署一个Redmine用于研发部,同时升级工作室的Redmine ...

  10. nginx源码分析——数组

    ngx_array.h /* * Copyright (C) Igor Sysoev * Copyright (C) Nginx, Inc. */ #ifndef _NGX_ARRAY_H_INCLU ...