Write a program that reads two integers a and b and prints the largest value of them. Numbers are integers from 1 to 1000. When solving a problem, you can only use integer arithmetic operations +, -, *, //, %, =. You cannot use nonlinear constructions: branching, loops, functions for calculating the module, extracting the square root.
Write a program that reads two integers a and b and prints the largest value of them. Numbers are integers from 1 to 1000. When solving a problem, you can only use integer arithmetic operations +, -, *, //, %, =. You cannot use nonlinear constructions: branching, loops, functions for calculating the module, extracting the square root.
Using the max function is prohibited!
Input data
Two integers a and b are entered .
Output
Print the answer to the problem.
a = int(input("Enter the first integer (a): "))
b = int(input("Enter the second integer (b): "))
# Calculate the sign of (a - b)
sign = (a - b) // ((a - b) // 2 + 1)
# Calculate the largest value
result = a - sign * ((a - b) // 2)
print("The largest value is:", result)
Preparing for the Junior Maths Challenge?
Join a free weekly live lesson where I solve real JMC-style problems, explain key methods, and share what to focus on in your weekly practice.
You can join live or watch the replay - everyone is welcome.
📅 Every Tuesday
⏰ 18:30–19:30 (UK time)
💻 Live session (link sent by email)

This course guides you through the fundamentals of Python programming using an interactive Python library known as Turtle.

This course encompasses a range of Geometry topics such as coordinate and spatial geometry, introductory trigonometry, angles, parallel lines, congruent and similar triangles, polygons, circles, the Pythagorean Theorem, and more. Emphasis will be placed on reinforcing Algebra skills and enhancing critical thinking through problem-solving in both mathematical and real-world contexts.

Ask about our courses and offerings, and we will help you choose what works best for you.