Loops – Arithmetic – Problem #16
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Consider the infinite summation formula for calculating the value of ‘x’ as given below. Take two integer numbers ‘n’ and ‘k’ as inputs. Find out the value of ‘x’ by summing the first ‘n’ terms according to the formula correct to three decimal places. Hence, multiply the value of x with ‘k’ and consider the floor of the result, i.e the integer value immediately lower than the multiplication value, and check whether the floor value is a prime number or not. You have to display the value of ‘x’ correct up to three decimal places and print ‘Prime’ or ‘Not prime’ based on the primality of floor(x*k). You can calculate the floor value by any way you feel like. Also make sure to take appropriate variable data types. Read the question clearly, you will get all the necessary details about data types. x = (1 × 2)3 ((1 × 2)(1 + 2))2 + (2 × 3)3 ((2 × 3)(2 + 3))2 + (3 × 4)3 ((3 × 4)(3 + 4))2 + · · · (1) Example 1: Input: n=2 k=677 Output: 0.462 Not prime [Reason: As n=2, the value of ‘x’ as per the given formula considering only the first two terms correct upto three decimal places is 0.462. Now 0.462 x k=0.462 x 677=312.774. Consider the floor of the answer, i.e 312, which is not a prime number.]