Primorial - Editorial

http://www.codechef.com/CDCK2015/problems/PRMRL

Ankur Goel

Ankur Goel

Shuchita Garg

Easy

PREREQUISITES:

Factorial of a number

PROBLEM:

The Primorial of a number N is defined as the product of all the primes &#60&#61 N. You are asked to calculate the Primorial for a given value of N.
Note : Primorial For N&#61 1 is 1.

EXPLANATION:

Since you have to find the product of all the primes starting from 1 to the given number, you can use the same technique that is used in finding the factorial of a number i.e. Start from 2 to N and multiplying all the primes encountered between them.

• If the number is less or equal to 50.

Simply, you can extract all the prime numbers appearing between 1 and the given number. Then by multiplying all the extracted primes together, you can get the desired product.
• If the amount is greater than 50.

In this case, the product can't be obtained by using the 'multiply' operator to find the product as even the largest data type in c or c++ i.e. long long works till the value of 50 in case of Primorial of a number. Hence, for the number greater than 50, you have to design a new function that calculates the product.
### Problems that can be encountered
• Not getting the answer for number greater than 20?

Using the desired way, the answer for number greater than 20 exceeds the limit of integer data type. Instead use long long data type.
• Not getting the answer for number greater than 50?

Solution to number greater than 50 exceeds the limit of data type long long. Use alternate way to find the solution.