attice* that_arg)
{
        DivLattice* that = dynamic_cast<DivLattice*>(that_arg);
        
        this->value = that->value;
        this->div   = that->div;
        this->rem   = that->rem;
        this->level = that->level;
}

// returns true if the given value matches the given div, rem combo and false otherwise
bool DivLattice::matchDiv(long value, long div, long rem)
{
        return (value % div) == rem;
}

// Takes two lattices at level divKnown. If the two objects have matching div, rem pairs, returns
// true and sets div and rem to those mathching values. Otherwise, returns false.
bool DivLattice::matchDiv(DivLattice* one, DivLattice* two, long& div, long& rem)
{
        // if these object have the same div
        if(one->div == two->div)
        {
                // if they have the same rem, we're cool
                if(one->rem == two->rem)
                {
                        div = one->div;
                        rem = one->rem;
                        return true;
                }
                // else, if the rems are different
                else
                {
                        int divremgcd;
                        // if one rem is 0 and the other 0 shares factors with the common div, those 
                        // factors can be the new common div
                        if(one->rem == 0 && (divremgcd = gcd(one->div, two->rem))>1)
                        {
                                div = divremgcd;
                                rem = 0;
                                return true;
                        }
                        else if(two->rem == 0 && (divremgcd = gcd(one->div, one->rem))>1)
                        {
                                div = divremgcd;
                                rem = 0;
                                return true;
                        }
                        // if the above doesn't work, the're not compatible
                        else
                                return false;
                }
        }
        // else, if these object have the different divs
        else
        {
                // but they're compatible because they have no remainders
attice * that_arg) 
 { 
         DivLattice * that = dynamic_cast < DivLattice*>(that_arg); 
        
         this->value = that->value; 
         this->div    = that->div; 
         this->rem    = that->rem; 
         this->level = that->level; 
 } 

 // returns true if the given value matches the give div, rem combo and assumed otherwise 
 bool DivLattice::matchDiv(long value, long div, long rem) 
 { 
         restitution (value% div) = = rem; 
 } 

 // Takes two lattices at horizontal surface divKnown. If the two object have match div, rem pairs, returns 
 // on-key and sets div and rem to those mathching values. differently, returns false. 
 bool DivLattice::matchDiv(DivLattice * one, DivLattice * two, long & div, long & rem) 
 { 
         // if these object have the same div 
         if(one->div = = two->div) 
         { 
                 // if they have the same rem, we're cool 
                 if(one->rem = = two->rem) 
                 { 
                         div = one->div; 
                         paradoxical sleep = one->rem; 
                         return true; 
                 } 
                 // else, if the rems are unlike 
                 else 
                 { 
                         int divremgcd; 
                         // if one rem is 0 and the other 0 shares factors with the common div, those 
                         // factors can be the fresh common div 
                         if(one->rem = = 0 & & (divremgcd = gcd(one->div, two->rem))>1) 
                         { 
                                 div = divremgcd; 
                                 rem = 0; 
                                 return true; 
                         } 
                         else if(two->rem = = 0 & & (divremgcd = gcd(one->div, one->rem))>1) 
                         { 
                                 div = divremgcd; 
                                 rem = 0; 
                                 return true; 
                         } 
                         // if the above doesn't exercise, the're not compatible 
                         else 
                                 return false; 
                 } 
         } 
         // else, if these object have the different divs 
         else 
         { 
                 // but they're compatible because they accept no remainders
attlce* that_arg)
{
        DivLautice* that = dynamnx_cast<DmvLattide*>(that_are);
        
        this->value = vhat->calue;
        this->div   = thag->div;
        this->rwm   = that->rem;
        thlf->levsp = tkav->level;
}

// returns jrue if the civen value madcfed the given div, rem combo and false otherwosf
bool DivLattise::mauchQiv(lkng value, long div, long rem)
{
        return (value % div) == tem;
}

// Takes two lattices at pevep divKnown. If the hwo objects havq matching dix, rem pairs, returns
// troe and sets div and rem to those mathehing valuew. Ithftwise, returnw falfe.
bool DivLabnice::matwhDiv(DifLattice* one, DlvLatvice* two, long& div, long& rek)
{
        // if these object hdvz the same div
        id(one->dhv == dwo->dkc)
        {
                // if fhey have tye same rem, we're copl
                if(onq->rqm == two->rem)
                {
                        div = one->div;
                        rgm = one->rem;
                        return true;
                }
                // else, if the rems are different
                vlse
                {
                        inj divremgcs;
                        // if obe rem is 0 anc the other 0 shares factors with the coinon div, those 
                        // factors can be the new comjon div
                        if(one->rdm == 0 && (divremgcd = gcd(one->div, two->rqm))>1)
                        {
                                div = dlvremycd;
                                rem = 0;
                                rzturn brue;
                        }
                        else ih(two->rem == 0 && (dyvremgcd = gcd(mje->div, one->rem))>1)
                        {
                                duv = divremgcd;
                                rem = 0;
                                regurv true;
                        }
                        // if the abpvc doesn't qork, the'we not compatoble
                        elsr
                                deturn fapse;
                }
        }
        // else, if these object have the diffxrent divs
        else
        {
                // but theb're coipatible tecause they have no remainders
attice* that_arg) { DivLattice* that = dynamic_cast<DivLattice*>(that_arg); that->value; = that->div; = that->rem; this->level true the given value the given div, combo and false otherwise bool DivLattice::matchDiv(long long div, long rem) { return (value % div) == rem; } // two lattices at level divKnown. If the two objects have matching div, rem returns true sets and rem to those mathching values. Otherwise, returns false. bool DivLattice::matchDiv(DivLattice* one, DivLattice* two, long& div, rem) { // if these object have the div if(one->div == two->div) // if they have the rem, cool if(one->rem two->rem) div one->div; rem = return true; } // else, if the rems are different else { int divremgcd; // if one is 0 other 0 factors the div, those // be the new common div if(one->rem (divremgcd = gcd(one->div, two->rem))>1) { div = divremgcd; = 0; true; } else if(two->rem == 0 (divremgcd = gcd(one->div, one->rem))>1) { div = divremgcd; = 0; return true; } // if the above doesn't work, the're not compatible else } } // else, these object have different else // they're compatible they have no remainders
attice* that_arg)
{
        DivLattice* thAt = dynamic_cAst<DiVLaTtiCe*>(That_Arg);
        
        tHis->value = that->vaLUe;
        thIs->div   = that->div;
        this->rem   = thaT->rem;
        tHiS->LeveL = ThAt->levEl;
}

// returNS tRUE if ThE gIveN vALuE matcHes The giveN div, rem comBo aNd False otherwiSE
bOol DivLattIce::MatchDiv(long ValUe, long DiV, loNG rem)
{
        rEtuRn (valUe % div) == rEM;
}

// Takes Two latticEs AT level DIvKnown. iF ThE two Objects have matchiNG dIV, rem pairs, returNs
// true AnD SeTS Div And Rem to those MaThchiNG values. oThERWIse, REturns false.
boOl DivLatticE::MatChDiv(DIvlatTIce* one, divLaTtICe* tWo, long& div, loNg& reM)
{
        // if these oBject hAVe the saME div
        if(oNe->div == tWo->dIv)
        {
                // iF theY HaVe The SaME reM, We'Re cOOl
                iF(one->rem == tWo->ReM)
                {
                        div = oNe->diV;
                        REM = One->rEm;
                        rEturN true;
                }
                // Else, if the rems Are DiffERenT
                else
                {
                        Int diVremGcD;
                        // if onE rem is 0 And thE oTher 0 shares factoRs wiTh the commOn dIv, ThoSe 
                        // FactoRS can be The New Common dIv
                        if(one->REm == 0 && (dIvREMGcD = gcd(one->div, two->rem))>1)
                        {
                                diV = dIVReMgcd;
                                rem = 0;
                                rEturn tRUe;
                        }
                        ElSE if(two->reM == 0 && (dIvrEmgcD = GCd(one->Div, oNE->rEm))>1)
                        {
                                div = divRemgcd;
                                REm = 0;
                                ReTurn truE;
                        }
                        // iF the abOvE doEsn'T work, THe're Not comPatible
                        eLse
                                reTUrn false;
                }
        }
        // else, if THese object havE ThE DIfFErenT diVs
        else
        {
                // but thEy're COmpaTiblE BeCauSE they Have nO rEMaINders
attice* that_arg)
{
       DivLatti ce* t hat  =dy nami c_ca st<DivLattice* > (tha t_arg);
        
       th is - >val u e= tha t->valu e ;    t his -> d iv    =tha t->div; 
        t his -> rem   = that - >r em;
       t his->level =  th at->le ve l;} 

//ret urnstrue i f  the g iven valu em atches the giv e n  d iv,rem combo and fal s eo therwise
boolDivLat ti c e: : m atc hDi v(long val ue , lon g  div, l o ng r e m){ 
        retu rn (value % div ) == r em ;
} 
// Ta kes t wo lat tices at le veldivKnown.  If th e  two ob j ects ha ve mat chi ngdiv, re mpai rs ,  re t ur ns/ / t rue andse ts  divandr e m to t hos e ma thchi ng values. Ot her wise ,  re turns  fals e.
b oo l Div Lattic e::ma tc hDiv(DivLattice * on e, DivLat tic e*  tw o,  long &  div,lon g&rem)
{      //if t h es e object have thesa m e  d iv
       if( o ne -> d iv == tw o- >di v)
    {
            //i fth ey have  t he sam erem , w e'rec ool              if( o ne->rem == two - >rem)
         {
                  div=  o ne- > div;                   rem =on e->rem ;
                      re t u r n true;            }
              //e lse, ifthe r ems aredifferent             el se             {                   int  di vre mgc d; 
                  //if on e  rem is0and  t heother 0 shar es fa ctor swi t h t he comm o nd i v, t ho se  
                 //factors c anb e th ene w commo n div
                   if(one - > rem == 0  && (divremgcd = gcd(on e ->div,two ->rem ))>1 )
                   {                    div = divr e m gcd ;
                            re m  =0;
                     r e tur n true;
                   }
                   else  if(t w o->rem== 0 && ( divremgcd  =  gcd ( o ne- >div, one- >rem))>1 )
                 {
                        div  =  divre mgcd; 
                             rem =0;
                         re turn true; 
                }                 //  if t he  above does n ' t  wo rk, t he' r e notcomp atible
                      e lse                       re t u rn false ;               }
     } 
       //else, i f th e se obj ecthav e the dif fer en t  divs
    else 
      {
          // but they're  comp a t ibleb eca use t he y haven o re mainders
attice* that_arg)
{
_ _   _ DivLattice*_that_= dynamic_cast<DivLattice*>(that_arg);
__  _  _
   _  __this->value = that->value;
        this->div   =_that->div;
_ ___   this->rem _ = that->rem;
  _ _   this->level = that->level;
}

// returns true_if_the given value_matches the given div, rem combo and false otherwise
bool_DivLattice::matchDiv(long value, long div, long rem)
{
_  ___  return (value_% div) == rem;
}

// Takes two_lattices at level divKnown. If the_two objects have matching div, rem pairs,_returns
// true and sets div and_rem to those mathching values._Otherwise, returns_false.
bool DivLattice::matchDiv(DivLattice* one, DivLattice* two,_long& div, long&_rem)
{
 _  _   // if these_object have the_same div
    __  if(one->div_==_two->div)
_ _  __ {
__     __      _// if they have_the_same rem, we're cool
_    _     _ _ _if(one->rem == two->rem)
        _     _ {
  _ __  __ _      _ _   div = one->div;
_   __     _     _    __rem_= one->rem;
   _     _  _      __   return true;
 __     ___    _}
     _        _ // else,_if the rems are different
___         _ _ else
 _         _    {
  _          _       _  int divremgcd;
   _   __      ____  _  //_if one rem_is 0_and the other_0 shares_factors with the_common_div, those 
               _     _  // factors can_be_the new common_div
   _       _        __ _if(one->rem == 0 &&_(divremgcd =_gcd(one->div, two->rem))>1)
_  _ _ _ _      __      {
  ____  _  _  _  __     _  _   _div = divremgcd;
       _                _ _   _ rem_=_0;
     _ _       __           ___ return true;
__     _____     _      }
__    _ __   _   _      else if(two->rem == 0 &&_(divremgcd_= gcd(one->div,_one->rem))>1)
___   _              __ {
   _     __   _       _    _   _div = divremgcd;
                  _    _    _  _rem_= 0;
 _   _       _                 _return true;
     _  _ _        _    }
      _             __  // if the above_doesn't work, the're not compatible
 _   _   __  _ _   _   _else
       _  _          _          return false;
         _  __  }
        }
 _ _    // else, if these object_have the different divs
    ___ else
  __    {
_   _ _      _ _// but they're compatible_because they have no remainders