zoukankan      html  css  js  c++  java
  • 数论

    我只能说这个数论定理对我一脸懵比,哦不对,是我对这个数论定理一脸懵比,暂时

    只准备记住模板就好了,求最小逆元的时候可以用一下,如果mod为素数而且不要求

    最小的话还是用费马小定理吧,对了还是要说一下,这个模板中exgcd(扩展欧几里德)

    的返回值是gcd(最大公约数),其中x才是要求的逆元,而且一求出来时并不是最小

    而且还有可能是负数,有点分类讨论了,不过我找模板的时候把分类讨论那里用一个更

    优的方案代替了(也是找的),用的时候注意点,不说了,我还是准备懵比去吧= =

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<vector>
    #include<queue>
    #include<cctype>
    using namespace std;

    #define Int __int64
    #define INF 0x3f3f3f3f

    int exgcd(int a, int b, int &x, int &y) {
      if (b == 0) {
        x = 1;
        y = 0;
        return a;
      }
      int gcd = exgcd(b, a%b, x, y);
      int t = y;
      y = x - a/b*y;
      x = t;
      return gcd;
    }
    int main()
    {
      //freopen("input.txt", "r", stdin);
      int n, m, x, y;
      while (scanf("%d%d", &n, &m) != EOF) {
        int gcd = exgcd(n, m, x, y);
        int q = m / gcd;
        x = ((x % q) + q)%q;
        printf("%d ", x);
      }
      return 0;
    }

  • 相关阅读:
    SQL Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问
    谷歌浏览器扩展程序manifest.json参数详解
    获取天气api
    UVA 10385 Duathlon
    UVA 10668 Expanding Rods
    UVALIVE 3891 The Teacher's Side of Math
    UVA 11149 Power of Matrix
    UVA 10655 Contemplation! Algebra
    UVA 11210 Chinese Mahjong
    UVA 11384 Help is needed for Dexter
  • 原文地址:https://www.cnblogs.com/steamedbun/p/5757769.html
Copyright © 2011-2022 走看看