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

optimized code #282

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Anshuman7080
Copy link

Removed Unused Includes: Removed <bits/stdc++.h> in favor of only the necessary headers (, , and ). This makes it clearer which libraries are actually being used.

Simplified Power of 2 Check: Instead of using log2 and checking conditions to see if n is a power of 2, I replaced it with a more straightforward bit manipulation check (n & (n - 1)) == 0, which is a standard way to check if a number is a power of two.

Using Vector: Replaced the static array with a std::vector to handle powers of two dynamically, making the code cleaner and avoiding arbitrary limits.

Efficiently Handling Input and Output: Used ios_base::sync_with_stdio(false) and cin.tie(nullptr) to speed up the input and output operations, which is especially useful for competitive programming.

Cleaner Logic: Removed unnecessary variables and streamlined the logic for summing powers. The for loop constructs and conditions are made clearer.

Removed Redundant Code: The commented-out sections and unnecessary calculations were removed to simplify the overall logic and improve readability.

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

Successfully merging this pull request may close these issues.

1 participant