@iro_miya While it's true that you can implement sums using a for loop, it can be optimized using basic summation identities. More specifically
\displaystyle{\sum^k_{n=0}3n = 3\sum^k_{n=0}n = 3\left(\sum^{k-1}_{n=0}n + k\right) = 3\left(\frac{k(k-1)}{2}+k\right)}
Where k \in \mathbb{Z}⁺, k > 0. So you can simply use this generic formula and save yourself a for loop.
The same can be applied to the multiplication as well, although in this case how much computational cost you save will depend on how the machine calculates the factorial.
\displaystyle{\prod^k_{n=1}2n = 2\prod^k_{n=1}n = 2(k!)}
Embed Notice
HTML Code
Corresponding Notice
- Embed this notice
【Ξnigmatico】:misskey: (enigmatico@mk.absturztau.be)'s status on Friday, 12-Jul-2024 19:12:43 JST【Ξnigmatico】:misskey: