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

ENGE602 Mathematics for Software Engineering 1 Week 4 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 set1; 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 1001 sets of integers; e.g. unsigned max =1000; vector< set > prime_factors (max +1); and fill each set with the prime factors of the vector index, such that prime_factors[j] 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=2 and insert the number 2 into the sets of prime factors of all multiples of 2. Then repeat for all prime numbers, noting that if the set prime_factors[k] 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 set1; set1.insert(3); seti.insert(4); seti.insert(5); set set2; set2.insert(4); set2.insert(5); set2.insert(6); set intersection; set_intersection (setl.begin(), set1.end(), set2.begin(), set2.end(), inserter(intersection, intersection.begin())); cout << "The intersection has << intersection.size()<<" elements:" << endl; set:iterator it; for (it-intersection.begin(); it!=intersection.end(); ++it) cout <<''<< it; cout << endl; set union12; set_union (set1.begin(), setl.end(), set2.begin(), set2.end(), inserter (union 12, union12.begin())); cout << "The union has < union 12.size()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!