Math Teacher's Worry (Hard)
Time limit1sMemory limit1024 MB
Given a positive integer n, factor n x^2 + (n+1)x - (n+2) over the integers and print (a, b, c, d), or -1 if no factorization exists.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
This problem is a harder version of Math Teacher's Worry (Easy). You can solve this problem and submit its correct code to Math Teacher's Worry (Easy) to get accepted.
Teacher Hyeongjun Cha was thinking about an interesting problem as usual. He came up with a problem that asks to factor the quadratic over the integers, for a positive integer .
For small , he could work it out by hand. As grew, the problem became hard.
So the teacher gave the problem to Dohun, who is not strong at math but writes code as instructed. However, Dohun has only copied and pasted code that ChatGPT gave him, and he can barely print "Hello World!". So he asked ChatGPT to write the code, as he usually does.
But the internet went down while he was waiting for the answer.

The image shows the moment the internet cut out while Dohun was asking ChatGPT to write a program.
Help Dohun write a program that factors over the integers.
Input
The first line contains a positive integer .
Output
If cannot be factored over the integers, print -1. Otherwise, print four integers , , , separated by spaces, which means . If there are several valid tuples, print any one of them.
Constraints
.