Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Overview This assignment will exercise your ability to utilize control statements for C++ and to write some simple functions. Background Prime numbers, those numbers

Assignment Overview

This assignment will exercise your ability to utilize control statements for C++ and to write some simple functions.

Background

Prime numbers, those numbers who have as integer divisors only the value 1 and the number itself, are a type of number that has been known since antiquity (Euclid's Elements for example, circa 300 BC).

However, sometimes we can describe numbers as relatively prime, that is numbers that share no factors except 1

Euler, one of the world's great est mathematicians, described a function which eventually became

associated with the Greek letter j and was subsequently called Euler's totient.

The idea is this:

Given an integer number

n >= 1, for every number d in the range 1 ...n check to see if each d is relatively prime to n. If so,then d is a totative of the sequence, and we increase the count of the totient function j by 1.

To do this we need a method to check the "relative primeness" of two numbers. Though there are better

ways, a simple way is the greatest common divisor (gdc) method, and an easy way to do that was propose by Euclid more than 2300 years ago ,appearing in his book Elements (300BC). If the gcd of two numbers if 1, then they are relatively prime.

Here is an example. Let us say we would like to calculate j(9). We would check every integer between1 and 9 and observe the following:

-the gcd (1,9) is 1, 1 is a totative of 9, j is 1

-the gcd (2,9) is 1, 2 is a totative of 9, j is 2

-gcd (3,9) is 3, 3 is not a totative of 9, no change to j

-etc.

In this sequence 3,6,9 are not totatives of 9 (they all have a gcd 1),j (9) has a value of 6 and the totative list of 9 is 1,2,4,5,7,8.

Project Description / Specification

For this program we will do re

-directe d input.

Input

Each test case is an individual file

Each test case contains two lines:

o first line, two integers each separated from the other by a s ingle space. You are to calculate the gcd of these two numbers

o second line, a single integer. You will calculate j and provide a list of totatives for this number

Output for each test case will be:

On the first line, the gcd of the first two numbers

On the second line the list of totatives. Each number is separated from its neighbor by a single

space.

On the third line, the value of j for the second line number

Requirements

1.If any input number from the test case is not an integer >= 1, print only the word Error on one line for that case and nothing else.

2.You cannot count on the order of the two gcd numbers, and order matters in the algorithm. You

have to check and place them in the correct order to make your calculation

3.Write a function gcd that takes two argument long types and returns a long , the gcd of the two arguments.

Euclid's algorithm is easily found on the web, go look for it!

4.Write a function phi that takes a single long argument and returns a long, the totative count for the range from 1... argument.

a.Note that the function will have to print the totatives as they are found.

b.Each number in the totative list is separated from its neighbor by one space.

5. Write the main function to perform all of the tasks indicated, including gathering input and using the gcd and phi

function to make the calculation.

6.Place all code in a single file named proj02.c

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

When should the last word in a title be capitalized?

Answered: 1 week ago

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago