Answered step by step
Verified Expert Solution
Question
1 Approved Answer
solve in c + + There are three integers, x , y , and k , and a given integer n . Initially, x and
solve in c
There are three integers, and and a given integer Initially, and are zero, and is a fixed arbitrary constant.
Perform the following operation that consists of two steps in sequence until becomes zero.
Decrease by and increase by If is less than then is increased by and becomes zero
Decrease by ofts value and add the same to If of is not an integer, then take the greatest integer less than or equal to it ie its floor. Example: becomes becomes
Find the minimum value of such that after the above operations are finished on the given integer
Example:
Given Initially we have It is optimal to choose
is increased by is decreased by is increased by of nie of
SmExample:nGiven n Initially we have xy Itis optimal to choose k n X yx is increased by nisdecreased by n y is increased by of nie of y n n X y n x y n x y n X yx is increased by nis decreased by n yis increased by of nie of y is increasedby n is decreased by n nX y n X y n x yas n which is lesSthat k xis 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