Question: ENGE 6 0 2 Mathematics for Software Engineering 1 Week 4 Tutorial: Counting Coprimes Via Sets of Prime Factors Aim: This week, we will explore
ENGE Mathematics for Software Engineering Week Tutorial: Counting Coprimes Via Sets of Prime Factors Aim: This week, we will explore Euler's totient function, $n which counts the positive integers less than integer n that are relatively prime to n That is it counts the positive integers m template class, the set template class is a container provided by the C Standard Template Library. It behaves like a set, in that elements can be inserted only once. In this example code, note the following: set set; declares a set that contains elements of type unsigned unsigned integer set:iterator it; declares an iterator, which behaves like a pointer, a special object that is able to visit every element in a set Part A: Extend the example code to create a vector of sets of integers; eg unsigned max ; vector set primefactors max ; and fill each set with the prime factors of the vector index, such that primefactorsj is equal to the set of the prime factors of j Use a strategy similar to that used in the Sieve of Eratosthenes: start with j and insert the number into the sets of prime factors of all multiples of Then repeat for all prime numbers, noting that if the set primefactorsk is empty, then k is prime. Also note that a prime factor appears only once in the set of prime factors, even if it appears more than once in the factorization.#include cout #include set #include inserter using namespace std; int main set set; setinsert; seti.insert; seti.insert; set set; setinsert; setinsert; setinsert; set intersection; setintersection setlbegin setend setbegin setend inserterintersection intersection.begin; cout "The intersection has intersection.size elements:" endl; set:iterator it; for itintersection.begin; itintersection.end; it cout it; cout endl; set union; setunion setbegin setl.end setbegin setend inserter union unionbegin; cout "The union has union size
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
