Exemplo n.º 1
0
 public static BigInt Exp(int x, int y)
 {
     if (x == 0) return new BigInt("0");
     if (y == 0) return new BigInt("1");
     BigInt ret = new BigInt(x.ToString());
     for (int i = 0; i < y-1; i++) {
         ret = ret.Product(x);
     }
     return ret;
 }
Exemplo n.º 2
0
        public override object Run(RunModes runMode, object input, bool Logging)
        {
            int upperLimit = (int) input;
            BigInt.MaxIndex = 9;
            BigInt sumSquares = new BigInt("");
            for (int i = 1; i <= upperLimit; i++) {
                BigInt prod = BigInt.Exp(i, i);
                sumSquares = sumSquares.SumBigIntNumbers(new List<BigInt>{sumSquares, prod});
            }

            return sumSquares.Value;
        }
Exemplo n.º 3
0
        public override object Run(RunModes runMode, object input, bool Logging)
        {
            var upperLimit = (int) input;
            var distinctExponentials = new List<BigInt>();
            for (int a = 2; a <= upperLimit; a++) {
                var bigIntA = new BigInt(a.ToString());
                for (int b = 2; b <= upperLimit; b++) {
                    bigIntA = bigIntA.Product(a);
                    distinctExponentials.Add(bigIntA);
                }
            }

            return distinctExponentials.Distinct().Count();
        }
Exemplo n.º 4
0
        public static IEnumerable<BigInt> Sequence(BigInt upperLimit)
        {
            List<BigInt> sequence = new List<BigInt>();
            BigInt fibCur = new BigInt("1");
            BigInt fibPrev = new BigInt("1");

            sequence.Add(fibPrev);
            while (fibCur.CompareTo(upperLimit) < 0) {
                sequence.Add(fibCur);

                BigInt temp = new BigInt(fibCur.Value);
                fibCur = new BigInt("").SumBigIntNumbers(new List<BigInt> { fibCur, fibPrev });
                fibPrev = new BigInt(temp.Value);
            }
            return sequence;
        }
Exemplo n.º 5
0
        public BigInt SumBigIntNumbers(List<BigInt> stringNumbers)
        {
            var maxIndex = (MaxIndex!=0) ? MaxIndex : stringNumbers.Max(s => s.Value.Length) - 1;
              long carry = 0;
              BigInt result = new BigInt("");
              for(int i=0;i<=maxIndex;i++) {
            result = new BigInt(AddStringAtIndex(stringNumbers, i, ref carry).Value + result.Value);
              }

            var carryBigInt = new BigInt(carry.ToString());
            carryBigInt.StripLeadingZeros();
            result = new BigInt(carryBigInt.Value + result.Value);
            result.StripLeadingZeros();
              return result;
        }