Answer the question
In order to leave comments, you need to log in
How to solve a seemingly simple problem in python3?
Greetings
I came across a problem and I can not solve it in accordance with the conditions.
Task:
Write a program that reads two integers a and b and outputs the largest of them. Numbers are integers from 1 to 1000.
When solving the problem, you can use only integer arithmetic operations +, -, *, //, %, =. You can not use non-linear constructions: branches, loops, functions, methods.
Answer the question
In order to leave comments, you need to log in
For example offhand:
>>> a,b=94,54
>>> (a*(a//b) + b*(b//a))/(b//a+a//b)
94
>>> a,b=6,322
>>> (a*(a//b) + b*(b//a))/(b//a+a//b)
322
Hello.
1. There are two numbers, x and y (positive integers).
2. There is their difference, z ( z = x - y )
3. To find the largest of them, all you need to do is sum these two numbers and divide their differences by 2 :
4. The only "ambush" is that, due to the uncertainty of numbers, their difference can be a negative number (for example, x = 5, y = 853, x - y = - 848 ).
5. Therefore, we need to ensure that the difference, in any case, is positive.
6. For this we have this very differencewe raise it to the second power and extract the square root from the result - in order for the code to be less noisy, we divide this procedure into two stages: a) z = (x - y) ** 2 ; b) z = z ** .5
7. Final code:
z = (x - y) ** 2
z = z ** .5
max_num = (x + y + z) / 2
A = int(input())
B = int(input())
A1 = A // B
A2 = A % B
A3 = 0**(A - A2)
B1 = B // A
B2 = B % A
B3 = 0**(B - B2)
Max = A1 * B2 + A2 * B1 + B2 * A3 + A2 * B3 + A * A3**B3 * B3**A3
print(Max)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question