Coprime
InterviewTime limit1sMemory limit128 MB
For each n up to 1e9, count how many positive integers less than n share no common factor with n, handling several test cases until a 0.
- Level
Medium5 of 10
- Topics
- Number theory, Math, Implementation
- Solved
- No attempts yet
Problem
Given a positive integer , write a program that counts how many positive integers smaller than are coprime with .
Two integers and are coprime when there is no integer together with positive integers and such that and . In other words, their only common divisor is .
Input
The input consists of several test cases. Each test case is a single line containing one integer with .
The last line of the input contains and is not processed.
Output
For each test case, print on its own line the number of positive integers smaller than that are coprime with .