Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Telephone connections Given A houses in the city. You have to divide these houses into B localities such that every locality has at least
Telephone connections Given A houses in the city. You have to divide these houses into B localities such that every locality has at least one house. Also, every house in a locality should have a telephone connection wire with each of the other houses in the locality. You are given integers A and B. Print the minimum and the maximum number of telephone connections possible if you design the city accordingly. Function description Complete the function Minmax(). This function takes the following 2 parameters and returns the required answer: A: Represents the number of houses B: Represents the number of localities Input format for custom testing Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code The first line contains an integer A denoting the number of houses. The second line contains an integer B denoting the number of localities. Input format for custom testing Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code The first line contains an integer A denoting the number of houses. The second line contains an integer B denoting the number of localities. Output format Print the minimum and the maximum number of telephone connections possible if you design the city accordingly. Constraints 1 B A 109 5 Sample input E Sample output 10 10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Here is the Python code for the given question def minmaxA B If there is only one locality all houses are connected to each other if B 1 minconnections maxconnections AA12 else If there are more localities each locality will have at least one house The remaining houses are distributed evenly among the localities q r divmodAB B The minimum number of connections is when the remaining houses are distributed as evenly as possible minconnections Bqq12 rq The maximum number of connections is when all the remaining houses are in one locality maxconnections B1qq12 qrqr12 return minconnections maxconnections Read input A intinput strip Number of houses B intinput strip Number of localities Calculate and print the minimum and maximum number of telephone connections minconnections maxconnections minmaxAB printminconnections maxconnections Here is an Image of Python with current formatting Here is the output of the code Explanation for the given code 1 Function Definition The function minmax is defined with two parameters A and B A represents the number of houses and B represents the number of localities 2 Case of One Locality If there is only one locality B 1 all houses are connected to each other In this case both the minimum and maximum number of connections are calculated as AA12 which is the formula for the number of edges in a complete graph with A nodes each house is a node and each telephone connection ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started