In: Computer Science
5. Paint the ceiling You want to build yourself a house. The building company you hired can only build houses with sides from their specific set s. That means they can build you a square house or a rectangular one but if and only if its length and width belong to the set s. This month, they have a special promotion: they will paint the ceiling of a new house for free...but only if its area is not more than a. You want them to do it for free but you also want to be sure that the house will be comfortable and not too small. How many possible house configurations can you create to have the ceiling painted for free given the side lengths offered? There is a method to how the company decides what lengths of sides to produce. To determine n lengths of wall segments to offer, they start with a seed value s0, some variables k, b and m, and use the following equation to determine all other side lengths s[i]: s[i]=((k*s[i-1]+b) mod m)+1+s[i-1]) for 1 si
import java.util.Arrays;
import java.util.Scanner;
public class RoomCeiling {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner src=new Scanner(System.in);
int count=0;
System.out.println("Enter the value of n(no. of length sides offered):");
int n=src.nextInt();
int[] s=new int[n];
System.out.println("Enter the maximum area of ceiling(a):");
int a=src.nextInt();
System.out.println("Enter the seed value s0:");
s[0]=src.nextInt();
System.out.println("Enter the value of k:");
int k=src.nextInt();
System.out.println("Enter the value of b:");
int b=src.nextInt();
System.out.println("Enter the value of m:");
int m=src.nextInt();
for(int i=1;i<n;i++)
{
s[i]=(k*s[i-1]+b)%m+1+s[i-1];
}
Arrays.sort(s);
for(int i=0;i<n;i++)
{
for(int j=1;j<n;j++)
{
if(s[i]*s[j]<=a)
count++;
else
break;
}
}
System.out.println("Possible no. of combiation are:"+count);
}
}