有趣的东西

  1 template<int mod>
  2 struct modular
  3 {
  4     int data;
  5     inline modular<mod> operator+(modular<mod> b)
  6     {
  7         modular<mod> res;
  8         res.data=data+b.data;
  9         if(res.data>=mod)
 10             res.data-=mod;
 11         return res;
 12     }
 13     inline modular<mod> operator-(modular<mod> b)
 14     {
 15         modular<mod> res;
 16         res.data=data-b.data;
 17         if(res.data<0)
 18             res.data+=mod;
 19         return res;
 20     }
 21     inline modular<mod> operator*(modular<mod> b)
 22     {
 23         modular<mod> res;
 24         res.data=(long long)data*b.data%mod;
 25         return res;
 26     }
 27     inline void operator+=(modular<mod> b)
 28     {
 29         data+=b.data;
 30         if(data>=mod)
 31             data-=mod;
 32         return;
 33     }
 34     inline void operator-=(modular<mod> b)
 35     {
 36         data-=b.data;
 37         if(data<0)
 38             data+=mod;
 39         return;
 40     }
 41     inline void operator*=(modular<mod> b)
 42     {
 43         data=(long long)data*b.data%mod;
 44         return;
 45     }
 46     inline bool operator==(modular<mod> b) const
 47     {
 48         return data==b.data;
 49     }
 50     inline bool operator!=(modular<mod> b) const
 51     {
 52         return data!=b.data;
 53     }
 54     inline bool operator<(modular<mod> b) const
 55     {
 56         return data<b.data;
 57         }
 58     inline modular<mod> operator+(int b)
 59     {
 60         modular<mod> res;
 61         res.data=data+b;
 62         if(res.data>=mod)
 63             res.data-=mod;
 64         return res;
 65     }
 66     inline modular<mod> operator-(int b)
 67     {
 68         modular<mod> res;
 69         res.data=data-b;
 70         if(res.data<0)
 71             res.data+=mod;
 72         return res;
 73     }
 74     inline modular<mod> operator*(int b)
 75     {
 76         modular<mod> res;
 77         res.data=(long long)data*b%mod;
 78         return res;
 79     }
 80     inline void operator+=(int b)
 81     {
 82         data+=b;
 83         if(data>=mod)
 84             data-=mod;
 85         return;
 86     }
 87     inline void operator-=(int b)
 88     {
 89         data-=b;
 90         if(data<0)
 91             data+=mod;
 92         return;
 93     }
 94     inline void operator*=(int b)
 95     {
 96         data=(long long)data*b%mod;
 97         return;
 98     }
 99     inline bool operator==(int b) const
100     {
101         return data==b;
102     }
103     inline bool operator!=(int b) const
104     {
105         return data!=b;
106     }
107     inline void operator=(int b)
108     {
109         data=b;
110         return;
111     }
112 };

 

-fno-elide-constructors

posted @ 2018-03-07 13:53  hehe_54321  阅读(147)  评论(0编辑  收藏  举报
AmazingCounters.com