Coprimes
Practice
3.8 (41 votes)
Ad Hoc
Algorithms
Coprime
Easy
Greedy algorithms
Problem
71% Success 8359 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are provided an integer \(n\). Your task is to determine the largest integer \(a\) (\(a<n-1\)) that is a coprime of \(n\). This implies that \(gcd(a,n)=1\).
Input format
A single line that contains an integer \(n\)
Output format
Print the answer to the question.
Constraints
\(3 \leq n \leq 10^{3}\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
6 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:10
57 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:10
23 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Editorial