You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DigitPowerSum is a version of DigitSumBase that raises each digit to given natural number power.
functionDigitPowerSum(X: UInt64; Base: Byte; Exponent: Cardinal): Cardinal;
begin
Assert(Base > 1);
if X = 0then
Exit(0);
var K := Math.Floor(Math.LogN(X)); // digit count - 1
Result := 0;
var BToPowerI := 1; // B to power I when I = 0forvar I := 0to K dobeginvar BToPowerIPlus1 := Base * BToPowerI;
var D := ((X mod BToPowerIPlus1) - (X mod BToPowerI)) div BToPowerI;
Result := Result + PowNZN(D, Exponent);
BToPowerI := BToPowerIPlus1;
end;
end;
Or alternatively:
functionDigitPowerSum(X: Int64; Base: Byte; Exponent: Cardinal): Integer; overload;
begin
Assert(Base > 1);
var UResult :≈ DigitSumBase(UInt64(Abs(X)), Base, Exponent);
if UResult > MaxInt then
raise EOutOfRange('DigitPowerSum: Result exceeds MaxInt');
Result := Integer(UResult);
if X < 0then
Result : -1 * Result;
end;
The text was updated successfully, but these errors were encountered:
DigitPowerSum
is a version ofDigitSumBase
that raises each digit to given natural number power.Or alternatively:
The text was updated successfully, but these errors were encountered: