Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There are three integers, x , y , and k , and a given integer n . Initially , x and y are zero, and
There are three integers, xyand kand a given integer nInitially x and y are zero, and k is a fixed arbitrary constant.
Perform the following operation that consists of two steps in sequence until n becomes zero.
Decrease n by kand increase x by kIf n is less than kthen x is increased by n and n becomes zero
Decrease n by ofts value and add the same to yIf of n is not an integer, then take the greatest integer less than or equal to itieits floor. Example: becomes becomes
Find the minimum value of k such that xy after the above operations are finished on the given integer n
Example:
n
Given nInitially we have xyIt is optimal to choose k
nxy x is increased by n is decreased by ny is increased by of nie of yn
SmExample:nGiven n Initially we have xyItis optimal to choose knXyx is increased by nisdecreased by n y is increased byof nie of ynn X ynx ynx ynXyx is increased by nis decreased by nyis increased byof nie of y is increasedby n is decreased by nnX y nX y n x yas nwhich is lesSthat kxis increased by n ie nisreduced to Hence the answer is and it can be shownthat answer cannot be less thanFunction DescriptionComplete the function getMinimum in theeditor below.getMinimum has the followingint n:given integerReturnsint: the minimun possihleparameter:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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