Last active
July 13, 2021 12:24
-
-
Save slntopp/e2a7ac708b6485dbd8535b09ec66e6f6 to your computer and use it in GitHub Desktop.
Codewars Kata Attempt | Number of Proper Fractions with Denominator d | C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long long properFractions(unsigned long long n) { | |
if(n == 1) return 0; | |
unsigned long long d = n; | |
for(unsigned long long i = 2; i * i <= d; i++) { | |
if(d % i == 0) { | |
n = n / i * (i - 1); | |
while(d % i == 0) d /= i; | |
} | |
} | |
if (d > 1) n = n / d * (d - 1); | |
return n; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment