zoukankan      html  css  js  c++  java
  • 迈斯!啊呸~数学

    1.数论

    快速幂

    int po(int x,int y)
    {
        int ans=1;
        while(y)
        {
            if(y%2==1)ans=1ll*ans*x%p;
            x=1ll*x*x%p;
            y/=2;
        }
        return ans;
    }

    乘法逆元(保证模域p与求逆元的数互质)

    po(a,p-2);//a为需要求逆元的数

           

    扩展欧几里得(exgcd)

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #define ll long long
    using namespace std;
    ll exgcd(ll a,ll b,ll &x,ll &y)
    {
        if(b==0)
        {
            x=1;
            y=0; 
            return a;
        }
        exgcd(b,a%b,x,y);
        ll tx=x;
        x=y;
        y=tx-a/b*y;
    }
    int main()
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        ll x,y;
        exgcd(a,b,x,y);
        while(x<0)
        {
            x+=b;
        }
        x%=b;
        printf("%lld
    ",x);
        return 0;
    }

     acos(-1.0)是圆周率,或者是cmath库里的M_PI也是圆周率,只有15位有效数字。

  • 相关阅读:
    python count函数
    kubenetes服务发现
    k8s网络
    k8s创建pod流程
    openstack创建虚拟流程、各组件介绍
    生产者消费者问题
    Date类和Calendar类
    Timer定时器
    Java中的克隆
    注解
  • 原文地址:https://www.cnblogs.com/lcccAngelo/p/9968125.html
Copyright © 2011-2022 走看看