PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000014. Tối thiểu hóa sai lệch bình phương (Minimize Abs 2)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tối thiểu hóa sai lệch bình phương (Minimize Abs 2)
Minimize Abs 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a positive integer . Choose any two non-negative integers and , with no further restrictions on either number. Consider the sum of their squares and its absolute difference from .
Find the minimum possible value of over all choices of non-negative integers .
Input
- The only line contains the positive integer .
Output
Print one non-negative integer: the minimum value of .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
21
Output
1
Explanation
Choosing x=4 and y=2 yields x²+y²=16+4=20, with error |20-21|=1. No pair of non-negative integers has square sum 21, so the minimum is 1.