Skip to content

Function number_of_divisors(n) returns wrong results #5999

Closed
@yuanyanhui

Description

@yuanyanhui

https://github.com/TheAlgorithms/Python/blob/master/maths/basic_maths.py
Function number_of_divisors(n) returns wrong results, e.g., number_of_divisors(6) produces 2. Correct answer should be 4.
After factorization, if n is not 1, this means it's a prime which has two divisors, thus the result should be multiplied by 2.
Solution: add the following code before function returns (line 60),
if n > 1: div *= 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions