PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000029. Sắp chữ số và hiệu chia hết cho chín (Number Theory for Newbies)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Sắp chữ số và hiệu chia hết cho chín (Number Theory for Newbies)
Number Theory for Newbies
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Rearrange all digits of a positive integer to form the largest number and the smallest number , neither with leading zeros. Compute and express the difference as in the required format.
Input
One line with decimal integer .
Output
Print exactly A - B = D = 9 * Q, where and .
Subtasks
- Subtask 1 (20 points):
- Subtask 2 (30 points):
- Subtask 3 (50 points): (Phuoc Hung OJ version bound)
Examples
Input
3021
Output
3210 - 1023 = 2187 = 9 * 243
Explanation
The maximum arrangement is and the minimum without leading zeros is . Their difference is .