Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from TheAlgorithms:master#77

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
pull merged 2 commits intoAlgorithmAndLeetCode:masterfromTheAlgorithms:master
Sep 27, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletionsbit_manipulation/count_of_set_bits.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,11 +36,19 @@ namespace count_of_set_bits {
* @returns total number of set-bits in the binary representation of number `n`
*/
std::uint64_t countSetBits(
std ::int64_t n) { //int64_t is preferred over int so that
std ::uint64_t n) { //uint64_t is preferred over int so that
// no Overflow can be there.
//It's preferred over int64_t because it Guarantees that inputs are always non-negative,
//which matches the algorithmic problem statement.
//set bit counting is conceptually defined only for non-negative numbers.
//Provides a type Safety: Using an unsigned type helps prevent accidental negative values,

std::uint64_t count = 0; // "count" variable is used to count number of set-bits('1')
// in binary representation of number 'n'
//Count is uint64_t because it Prevents theoretical overflow if someone passes very large integers.
// Behavior stays the same for all normal inputs.
// Safer for edge cases.

int count = 0; // "count" variable is used to count number of set-bits('1')
// in binary representation of number 'n'
while (n != 0) {
++count;
n = (n & (n - 1));
Expand Down
9 changes: 0 additions & 9 deletionsmath/number_of_positive_divisors.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,6 @@
**/

#include <cassert>
#include <iostream>

/**
* Function to compute the number of positive divisors.
Expand DownExpand Up@@ -80,13 +79,5 @@ void tests() {
*/
int main() {
tests();
int n;
std::cin >> n;
if (n == 0) {
std::cout << "All non-zero numbers are divisors of 0 !" << std::endl;
} else {
std::cout << "Number of positive divisors is : ";
std::cout << number_of_positive_divisors(n) << std::endl;
}
return 0;
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp