Sorry, I am not good at math
But is there a mathematical formula that could replace the below code, i.e. to calculate the points given qid,points, and factor without a loop?
for (int i = 1; i < qid; i++)
{
points = points * factor;
}
How can I convert the above code into a mathematical formula than can be calculated in a single line without a loop
thanks.
assuming
pointsis initialized to1, it is equvalent topoints = factor^(qid-1), or for general case:points_after = points_before * factor^(qid-1)The loop repeats
qid - 1times [iget the values:1,2,...,qid-1, for valuei==qidyou do not multiple], and in each iteration you multiplepointsbyfactoreach time, so you multiple it by total offactor^(qid-1)