Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n个2的n次方之和 #253

Open
Sunny-117 opened this issue Nov 4, 2022 · 3 comments
Open

n个2的n次方之和 #253

Sunny-117 opened this issue Nov 4, 2022 · 3 comments

Comments

@Sunny-117
Copy link
Owner

No description provided.

@bearki99
Copy link

等比数列求和吧

@veneno-o
Copy link
Contributor

等比数列求和公式

  • Sn = a1 * (q**n - 1) / (q - 1)

@Liu6625
Copy link

Liu6625 commented Oct 18, 2023

function sumOfPowers(n) {
  let sum = 0;
  for (let i = 0; i < n; i++) {
    sum += Math.pow(2, i);
  }
  return sum;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants