/*************************************************************************** zmod.h - description ------------------- begin : Fri Jan 17 19:41:58 CST 2003 copyright : (C) 2003 by Daniel Eric Smith email : ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include class zmod{ int mod,num; public: zmod(int m) {mod=m; num=0;} zmod(int m, int n) {mod=m; num=n;} void set(int n); int put(); void conv(); zmod operator+(zmod m); zmod operator-(zmod m); zmod operator*(zmod m); friend istream& operator>>(istream& s, zmod& n); friend ostream& operator<<(ostream& s, zmod n); }; void zmod::set(int n) { if(n<0) { while(n<0) { n+=mod; } } num=n%mod; } int zmod::put() { return num; } void zmod::conv() { num=num%mod; if(num<0) { while(num<0) { num+=mod; } num=num%mod; } } /************* * ARITHMETIC * *************/ /*********** * * * ADDITION * * * ***********/ zmod zmod::operator+(zmod x) { zmod t(mod); t.num=(num+x.num)%mod; return t; } /************** * * * SUBTRACTION * * * **************/ zmod zmod::operator-(zmod x) { zmod t(mod); t.num=(num-x.num)%mod; t.conv(); return t; } /***************** * * * MULTIPLICATION * * * *****************/ zmod zmod::operator*(zmod x) { zmod t(mod); t.num=(num*x.num)%mod; return t; } /*************** * INPUT/OUTPUT * ***************/ istream& operator>>(istream& s, zmod& n) { s>>n.num; return s; } ostream& operator<<(ostream& s, zmod n) { n.conv(); s<