private bool _MakeTest(OmgNum testBase) { OmgNum numDec = (new OmgNum(m_tested)).Dec(); OmgNum tested = OmgOp.Pow(testBase, m_initialTested, m_tested); OmgNum iterationsLeft = new OmgNum(m_powerOfTwo); try { if (OmgOp.Equal(tested, OmgNum.GetConst(1)) || OmgOp.Equal(tested, numDec)) { return(true); } while (!iterationsLeft.IsZero()) { iterationsLeft.Dec(); var nwTested = OmgOp.Multiply(tested, tested, m_tested); tested.Release(); tested = nwTested; if (OmgOp.Equal(tested, numDec)) { return(true); } } return(false); } finally { numDec.Release(); tested.Release(); iterationsLeft.Release(); } }
private OmgNum _FindPow(ref OmgNum num, OmgNum factor) { OmgNum pow = 0.ToOmgNum(); while (true) { var divMod = OmgOp.DivMod(num, factor); if (!divMod.mod.IsZero()) { break; } pow.Inc(); divMod.mod.Release(); num.Release(); num = divMod.div; } if (pow.IsZero()) { throw new Exception(); } return(pow); }