Question: Below code is in python convert this code to c++ programming and post the program with output pics as well: import math def is_prime(n): if
Below code is in python convert this code to c++ programming and post the program with output pics as well:
import math
def is_prime(n): if n < 2: return False if n == 2: return True try: (d for d in xrange(2, long(math.sqrt(n))+1) if n % d == 0).next() except StopIteration: return True else: return False
def gen_prime(): n = 2 while True: if is_prime(n): yield n n += 1
def nth_prime(i): gp, p = gen_prime(), 0 for i in xrange(1, i + 1): p = gp.next() return p
def factors(n): def factors_aux(n, i): if is_prime(n): return [n] else: pi = nth_prime(i) if n % pi ==0: return [pi] + factors_aux(n/pi, i) else: return factors_aux(n, i+1) return factors_aux(n, 1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
