Problem G. Digit Power
Xem dạng PDFTrong trường hợp đề bài hiển thị không chính xác, bạn có thể tải đề bài tại đây: Đề bài
During the final days of preparation for the entrance exam in Computer Science at UMT University, a student named Son Tan set a clear study goal: to accumulate a total of N units of knowledge. Each day, Son Tan studies M units consistently. This means that after each day, his total accumulated knowledge increases by exactly M units. Initially, Son Tan has no knowledge (i.e., his accumulated knowledge starts at 0).
To fully complete his goal, Son Tan wants the total required knowledge N to be divisible by M (i.e., ~N~ mod ~M = 0~). If this condition is already satisfied, everything is simple! However, if ~N~ is not divisible by ~M~, Son Tan allows himself to swap at most one pair of digits in the decimal representation of N to form a new number ~N'~. He wants to know whether such a single swap can result in a number divisible by ~M~.
You are given the integers ~N~ and ~M~. Determine whether it is possible to swap at most one pair of digits in ~N~ to obtain a new number that is divisible by ~M~. If N is already divisible by ~M~, print 0. If a swap is needed, print 1 ~i~ ~j~, where ~i < j~ are the indices of the digits to swap (with the smallest possible ~i~, and among those, the smallest possible ~j~). Indices are 0-based, counted from right to left. If no valid swap can make ~N~ divisible by ~M~, print -1.
Input
A single line containing two integers ~N~ and ~M~, representing Son Tan original goal and his daily progress. ~1 ≤ N ≤ 10^50000~ (i.e., ~N~ may have up to 50,000 digits) and ~1 ≤ M ≤ 10^9~
Output
The minimal solution according to the problem's requirements.
Sample Input 1
12539 4
Sample Ouput 1
1 0 3
Sample Input 2
13579 3
Sample Ouput 2
-1
Sample Input 3
1200 25
Sample Ouput 3
0
Bình luận