public LongNum Add(LongNum num) { while (Length < num.Length) { _number.Insert(0, 0); } while (num.Length < Length) { num._number.Insert(0, 0); } var result = _number.Select((v, pos) => v + num._number.ElementAtOrDefault(pos)).ToList(); result.Insert(0, 0); for (int i = result.Count - 1; i >= 0; i--) { while (result[i] >= 10) { result[i - 1] += 1; result[i] -= 10; } } while (result[0] == 0) { result.RemoveAt(0); } return new LongNum(result); }
public LongNum Add(LongNum num) { while (Length < num.Length) { _number.Insert(0, 0); } while (num.Length < Length) { num._number.Insert(0, 0); } var result = _number.Select((v, pos) => v + num._number.ElementAtOrDefault(pos)).ToList(); result.Insert(0, 0); for (int i = result.Count - 1; i >= 0; i--) { while (result[i] >= 10) { result[i - 1] += 1; result[i] -= 10; } } while (result[0] == 0) { result.RemoveAt(0); } return(new LongNum(result)); }
public LongNum Pow(int n) { var result = new LongNum(this); var start = this.AsLong(); for (int i = 1; i < n; i++) { result = result.Mul((int)start); } return(result); }
protected override long GetCalculationResult() { var maxA = 100; var maxB = 100; var result = new HashSet <string>(); for (var a = 2; a <= maxA; a++) { for (var b = 2; b <= maxB; b++) { var num = new LongNum(a).Pow(b).ToString(); result.Add(num); } //Print("{0}", a); } //HashSet<int> return(result.Count); }
protected override long GetCalculationResult() { _longNums = _numbers.Select(n => new LongNum(n)).ToList(); //var s = _longNums[0].Add(_longNums[1]).Add(_longNums[2]); //Print("{0,55}", _longNums[0]); //Print("{0,55}", _longNums[1]); //Print("{0,55}", _longNums[2]); //Print("{0,55}", s); //var nine = new LongNum("9"); //var s = nine.Add(nine).Add(nine).Add(nine); //Print("{0,55}", s); //return 0; var result = new LongNum("0"); _longNums.ForEach(n => result = result.Add(n)); _longNums.ForEach(n => Print("{0,55}", n)); Print("{0,55}", result); var r = long.Parse(result.ToString().Substring(0, 10)); return(r); }
public LongNum(LongNum num) : this(num.ToString()) { }
public LongNum Pow(int n) { var result = new LongNum(this); var start = this.AsLong(); for (int i = 1; i < n; i++) { result = result.Mul((int)start); } return result; }