|
|
|
|
|
by SamReidHughes
2039 days ago
|
|
For example, starting from decimal representation, you can calculate the product of five digit numbers, ("abcde" * "fghij") with the following, where capitalized variables X and S are the magic O(1)-addition integer types: let X = to_magic_integer("abcde")
let y = "fghij".reverse()
let S = to_magic_integer("0")
for d = 0 to 4
for i = 1 to y[d]
S += X
end
X = X+X+X+X+X + X+X+X+X+X
end
return S
(You can implement to_magic_integer with basically the same algorithm in O(n).) |
|
> addition operations of numbers with log(n) bits deemed to take O(1) time.
not
> addition operations of numbers with n bits deemed to take O(1) time.