FunctionRacerProblemsRace

Count Coprimes

EasyMathPython, JavaScript, TypeScript, Java, C++

Two numbers are coprime when their greatest common divisor is 1. Return how many integers from 1 to n (inclusive) are coprime with n.

Example 1

n 10
returns 4

1, 3, 7 and 9.

Example 2

n 1
returns 1

gcd(1, 1) = 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems