Problem 187617 · easy · Phase 01 Prerequisites & Setup

Count the Coprimes

functions · gcd · loops

Two numbers are coprime when their greatest common divisor is 1. Write count_coprime(n) that returns how many integers k with 1 <= k <= n are coprime with n.

Examples

Input:  n = 10
Output: 4
Explanation: 1, 3, 7 and 9 share no factor with 10.

Input:  n = 7
Output: 6

Input:  n = 1
Output: 1

Constraints

  • 1 <= n <= 5000

Goals

  • Write a helper function and call it from another
  • Count how many values satisfy a condition
Starting Python…