示例#1
0
        internal void VerifyFactors()
        {
            Integer TestFactors = new Integer();
            TestFactors.SetToOne();
            for( int Count = 0; Count < FactorsArrayLast; Count++ )
              IntMath.Multiply( TestFactors, FactorsArray[Count].Factor );

            if( !TestFactors.IsEqual( OriginalFindFrom ))
              throw( new Exception( "VerifyFactors didn't come out right." ));
        }
示例#2
0
        // These bottom digits are 0 for each prime that gets
        // multiplied by the base.  So they keep getting one
        // more zero at the bottom of each one.
        // But the digits in BaseModArray only have the zeros
        // at the bottom on the ones that are smaller than the
        // modulus.
        // At BaseArray[0] it's 1, 1, 1, 1, 1, .... for all of them.
        // 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0
        // 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 1, 0, 0
        // 30, 30, 30, 30, 1, 7, 11, 13, 4, 8, 2, 0, 0, 0
        private void SetupBaseArray()
        {
            // The first few numbers for the base:
            // 2             2
            // 3             6
            // 5            30
            // 7           210
            // 11        2,310
            // 13       30,030
            // 17      510,510
            // 19    9,699,690
            // 23  223,092,870

            try
            {
            if( NumbersArray == null )
              throw( new Exception( "NumbersArray should have already been setup in SetupBaseArray()." ));

            BaseStringsArray = new string[ChineseRemainder.DigitsArraySize];
            BaseArray = new Integer[ChineseRemainder.DigitsArraySize];
            CRTBaseArray = new ChineseRemainder[ChineseRemainder.DigitsArraySize];

            Integer SetBase = new Integer();
            ChineseRemainder CRTSetBase = new ChineseRemainder( IntMath );

            Integer BigBase = new Integer();
            ChineseRemainder CRTBigBase = new ChineseRemainder( IntMath );

            BigBase.SetFromULong( 2 );
            CRTBigBase.SetFromUInt( 2 );
            string BaseS = "2";

            SetBase.SetToOne();
            CRTSetBase.SetToOne();

            // The base at zero is 1.
            BaseArray[0] = SetBase;
            CRTBaseArray[0] = CRTSetBase;
            BaseStringsArray[0] = "1";

            ChineseRemainder CRTTemp = new ChineseRemainder( IntMath );

            // The first time through the loop the base
            // is set to 2.
            // So BaseArray[0] = 1;
            // So BaseArray[1] = 2;
            // So BaseArray[2] = 6;
            // So BaseArray[3] = 30;
            // And so on...
            // In BaseArray[3] digits at 2, 3 and 5 are set to zero.
            // In BaseArray[4] digits at 2, 3, 5 and 7 are set to zero.
            for( int Count = 1; Count < ChineseRemainder.DigitsArraySize; Count++ )
              {
              SetBase = new Integer();
              CRTSetBase = new ChineseRemainder( IntMath );

              SetBase.Copy( BigBase );
              CRTSetBase.Copy( CRTBigBase );

              BaseStringsArray[Count] = BaseS;
              BaseArray[Count] = SetBase;
              CRTBaseArray[Count] = CRTSetBase;
              // if( Count < 50 )
            // Worker.ReportProgress( 0, CRTBaseArray[Count].GetString() );

              if( !IsEqualToInteger( CRTBaseArray[Count],
                             BaseArray[Count] ))
            throw( new Exception( "Bug.  The bases aren't equal." ));

              // Multiply it for the next BigBase.
              uint Prime = IntMath.GetPrimeAt( Count );
              BaseS = BaseS + "*" + Prime.ToString();
              IntMath.MultiplyUInt( BigBase, Prime );
              CRTBigBase.Multiply( NumbersArray[IntMath.GetPrimeAt( Count )] );
              }
            }
            catch( Exception Except )
              {
              throw( new Exception( "Exception in SetupBaseArray(): " + Except.Message ));
              }
        }
示例#3
0
        private void FindXTheHardWay( Integer B, Integer Temp, ulong A )
        {
            Integer CountX = new Integer();
            CountX.SetToOne();
            while( true )
              {
              if( Worker.CancellationPending )
            return;

              Temp.Copy( CountX );
              IntMath.Multiply( Temp, B );
              Temp.AddULong( A );
              IntMath.Divide( Product, Temp, Quotient, Remainder );
              if( Remainder.IsZero())
            {
            if( !Quotient.IsOne())
              {
              SolutionP.Copy( Temp );
              SolutionQ.Copy( Quotient );
              return;
              }
            }

              CountX.Increment();
              if( MaxX.ParamIsGreater( CountX ))
            {
            // Worker.ReportProgress( 0, "Tried everything up to MaxX." );
            return;
            }
              }
        }
示例#4
0
        internal void GetTraditionalInteger( CRTBase ToGetFrom, Integer ToSet )
        {
            try
            {
            if( CRTBaseArray == null )
              throw( new Exception( "Bug: The BaseArray should have been set up already." ));

            // This first one has the prime 2 as its base so
            // it's going to be set to either zero or one.
            if( ToGetFrom.GetDigitAt( 0 ) == 1 )
              ToSet.SetToOne();
            else
              ToSet.SetToZero();

            Integer WorkingBase = new Integer();
            for( int Count = 1; Count < ChineseRemainder.DigitsArraySize; Count++ )
              {
              int BaseMult = ToGetFrom.GetDigitAt( Count );
              WorkingBase.Copy( BaseArray[Count] );
              IntMath.MultiplyUInt( WorkingBase, (uint)BaseMult );
              ToSet.Add( WorkingBase );
              }
            }
            catch( Exception Except )
              {
              throw( new Exception( "Exception in GetTraditionalInteger(): " + Except.Message ));
              }
        }
        internal void GetTraditionalInteger( Integer Result )
        {
            try
            {
            Result.SetToOne();
            for( int Count = 0; Count < VectorValuesArrayLast; Count++ )
              {
              uint Exponent = VectorValuesArray[Count].Exponent;
              uint Prime = VectorValuesArray[Count].Prime;
              for( int ExpCount = 0; ExpCount < Exponent; ExpCount++ )
            IntMath.MultiplyULong( Result, Prime );

              }

            if( !ExtraValue.IsZero())
              IntMath.Multiply( Result, ExtraValue );

            }
            catch( Exception Except )
              {
              throw( new Exception( "Exception in ExponentVectorNumber.GetTraditionalInteger(): " + Except.Message ));
              }
        }