• 自动取模类


    #include <bits/stdc++.h>
    using namespace std;
    
    #define RG register int
    #define LL long long
    
    namespace Mod{
        class Modulus{
        public:
            static const LL mo=1000000007LL;
            LL num;
            static LL mod(LL x);
            static void read(Modulus &a);
            static LL expow(LL a,LL m);
            Modulus(const LL x=0LL):num(mod(x)){}
            Modulus(const Modulus &a):num(a.num){}
            void output(){printf("%lld",num);}
            void operator=(const LL x){num=mod(x);}
            void operator=(const Modulus &x){num=x.num;}
            Modulus operator+(const Modulus &rhs){return Modulus(mod(num+rhs.num));}
            Modulus operator-(const Modulus &rhs){return Modulus(mod(num-rhs.num));}
            Modulus operator*(const Modulus &rhs){return Modulus(mod(num*rhs.num));}
            Modulus operator/(const Modulus &rhs){return Modulus(mod(num*expow(rhs.num,mo-2)));}
            Modulus operator+(LL x){return Modulus(mod(num+x));}
            Modulus operator-(LL x){return Modulus(mod(num-x));}
            Modulus operator*(LL x){return Modulus(mod(num*x));}
            Modulus operator/(LL x){return Modulus(mod(num*expow(x,mo-2)));}
            Modulus operator^(LL x){return Modulus(expow(num,x));}
            friend ostream &operator<<(ostream &output,const Modulus &x){
                output<<x.num;return output;
            }
            friend istream &operator>>(istream &input,Modulus &x){
                input>>x.num;
                return input;
            }
        };
    
        LL Modulus::mod(LL x){
            if(x<0) return (x%mo+mo)%mo;
            else if(x>=mo) return x%mo;
            return x;
        }
    
        void Modulus::read(Modulus &a){
            LL X=0,w=0; char ch=0;
            while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
            while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
            a.num=mod(w?-X:X);
        }
    
        LL Modulus::expow(LL a,LL n){
            LL x=1,p=mod(a);
            while(n){
                if(n&1) x=mod(x*p);
                p=mod(p*p);
                n>>=1;
            }
            return x;
        }
    };
    
    int main(){
        Mod::Modulus a,b,c;
        Mod::Modulus::read(a);
        Mod::Modulus::read(b);
        Mod::Modulus::read(c);
        cout<<a*b/c<<endl;
    
        return 0;
    }
    
  • 相关阅读:
    js全选,全不选,反选练习
    linux查看系统的一些命令,留着用
    JAVA中native方法
    应该被记住的 8 位 Java 人物
    iframe里面的iframe无法左右对齐的解决方法
    sql语句,查找合并后的结果
    地址路径过深时的处理方式
    惠普中国CEO孙振耀退休感言
    js获得readOnly属性
    直接加载错误页面void com.opensymphony.xwork2.ActionSupport.addActionError(String anErrorMessage)
  • 原文地址:https://www.cnblogs.com/AEMShana/p/13909570.html
Copyright © 2020-2023  润新知