[Codewars] Can you really count divisors?

Can you really count divisors?

  • Time :
  • Space :
1
2
3
4
5
6
7
long countDivisors(const long& n) {
long long sum = 0;
for (long long i = 1; i <= sqrt(n); i++) {
sum += n / i;
}
return 2 * sum - (long long)sqrt(n) * (long long)sqrt(n);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/29/PS/Codewars/can-you-really-count-divisors/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.