public BigInteger T3Slow(BigInteger n) { var sum = (BigInteger)0; var root3 = IntegerMath.FloorRoot(n, 3); if (threads == 0) { sum += T3Worker(n, root3, 0, 1); } else { var tasks = new Task[threads]; for (var i = 0; i < threads; i++) { var thread = i; tasks[i] = new Task(() => { var s = T3Worker(n, root3, thread, threads); lock (this) sum += s; }); tasks[i].Start(); } Task.WaitAll(tasks); } return(3 * sum + IntegerMath.Power(T1(root3), 3)); }
public static Rational CeilingRoot(Rational a, Rational b) { var c = FloorRoot(a, b); if (IntegerMath.Power(a, c) != c) { ++c; } return(c); }
private BigInteger T3Worker(BigInteger n, BigInteger root3, int worker, int workers) { var s = (BigInteger)0; for (var z = (BigInteger)1 + 2 * worker; z <= root3; z += 2 * workers) { var nz = n / z; var sqrtnz = IntegerMath.FloorSquareRoot(nz); var t = hyperbolicSum[worker].Evaluate(nz, (long)z + 2, (long)sqrtnz); s += 2 * t - IntegerMath.Power(T1(sqrtnz), 2) + T1(nz / z); } return(s); }
public BigInteger F3(BigInteger n) { //Console.WriteLine("F3({0})", n); var s = (BigInteger)0; var dmax = IntegerMath.FloorRoot(n, 3); for (var d = 1; d <= dmax; d += 2) { var md = mobius[d]; if (md == 0) { continue; } var term = T3(n / IntegerMath.Power((BigInteger)d, 3)); s += md * term; } Debug.Assert((s - 1) % 3 == 0); return((s - 1) / 3); }
public override Rational Power(Rational a, Rational b) { return(IntegerMath.Power(a, b)); }
public override uint Power(uint a, uint b) { return(IntegerMath.Power(a, b)); }
public override Int128 Power(Int128 a, Int128 b) { return(IntegerMath.Power(a, b)); }
public override ulong Power(ulong a, ulong b) { return(IntegerMath.Power(a, b)); }
public override BigInteger Power(BigInteger a, BigInteger b) { return(IntegerMath.Power(a, b)); }