Ad
  • Default User Avatar

    The given implementation can be improved by just changing the upperbound of the range to be int(math.sqrt(n))+2

    Still probably not the most efficient approach, but there's no point in checking numbers above the sqrt(n)+1.

    Edit:
    Actually I think it does not matter since the return statement will exit the function before those higher values are tested.

  • Custom User Avatar

    Your code is much more efiicient

  • Custom User Avatar

    What you said is correct, if the number has a large factor, it will be time consuming.Please refer to my solution.