Mod& Mod::operator*=(const Mod& m){ //repeated doubling is used for efficiency and prevention of overflow long b = m.val(); Mod temp = 0; while (b > 0){ if (b % 2 == 1){ temp += *this; } *this += *this; b = b / 2; } x = temp.val(); return *this; }
bool operator!=(const Mod& a, const Mod& b) { return a.val() != b.val(); }
bool operator==(const Mod& a, const Mod& b) { return a.val() == b.val(); }
Mod::Mod(const Mod& m) { this->x = m.val(); }
bool operator!=(long t, const Mod& m){ return (!(t == m.val())); }
bool operator!=(const Mod& a, const Mod& b){ return (!(a.val() == b.val())); }