# CHFFIELD | Editorial

Author and Editorialist: Prateek Kumar

PREREQUISITES:

Basic Maths

PROBLEM:

You have to take the two dimensions of the rectangular field as input. The dimension that is a prime number is to be reduced to the closest non prime number. If the dimension can not be reduced to a non prime, then reduce it to 1. After this calculate the area of the resultant field. You have to do this for a number of test cases.

EXPLANATION:

The problem was simple, use the following algorithm to solve it:

1. Take t as input
2. For i=1 to t:
3. ``````Take L and B as input<BR>
``````
4. ``````If L<=3 then L=1<Br>
``````
5. ``````If B<=3 then B=1<BR>
``````
6. ``````If L>3 and Check_prime(L) is true then L=L-1<BR>
``````
7. ``````If B>3 and Check_prime(B) is true then B=B-1<BR>
``````
8. ans=L*B
9. print ans

Check_prime(n)

Check if the number is divisible by any number till sqrt(n)

If divisible, then composite

Else prime

AUTHOR’S SOLUTIONS:

http://www.codechef.com/viewsolution/5441213
( The author’s solution uses a different method for prime checking, it uses prime generation)