Write a python function that takes a positive integer n as an argument. This function will return the number of positive integers less than n that are co-prime to n. Co-prime Numbers: Two numbers are coprime to each other if they don't have any common divisor except 1.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question
Write a python function that takes a positive integer n as an
argument.
This function will return the number of positive integers
less than n that
are co-prime to n.
Co-prime Numbers: Two numbers are coprime to each
other if they don't have
any common divisor except 1.
Sample Input 1:
1
Sample Output 1:
Reason: Since 1 is the smallest positive integer, there
exists no positive
integer that is less than and coprime to 1.
Sample Input 2:
2
Sample Output 2:
1
Reason: Only 1 doesn't share any common divisor (except
1 itself) with 2.
Also, 1 < 2.
Sample Input 3:
Sample Output 3:
Reason: Namely, the two coprime numbers to 6 are 1 and
5.
Sample Input 4:
36
Sample Output 4:
12
Reason: The numbers coprime to 36 are 1, 5, 7, 11, 13, 17,
19, 23, 25, 29,
31 and 35
Transcribed Image Text:Write a python function that takes a positive integer n as an argument. This function will return the number of positive integers less than n that are co-prime to n. Co-prime Numbers: Two numbers are coprime to each other if they don't have any common divisor except 1. Sample Input 1: 1 Sample Output 1: Reason: Since 1 is the smallest positive integer, there exists no positive integer that is less than and coprime to 1. Sample Input 2: 2 Sample Output 2: 1 Reason: Only 1 doesn't share any common divisor (except 1 itself) with 2. Also, 1 < 2. Sample Input 3: Sample Output 3: Reason: Namely, the two coprime numbers to 6 are 1 and 5. Sample Input 4: 36 Sample Output 4: 12 Reason: The numbers coprime to 36 are 1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31 and 35
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning