Editorial for Số có 2 chữ số
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Spoiler Alert
Approach 1
-
Để lấy \(k\) chữ số cuối của \(n\), ta lấy \(t \equiv n\) \((mod\) \(10^k)\) \(\Leftrightarrow\) \(t\) \(=\) \(n\) \(mod\) \(10^k\) (mod là phép chia lấy dư)
-
Để xóa \(k\) chữ số cuối của \(n\), ta lấy \(n = \lfloor\frac{n}{10^k}\rfloor\) \(\Leftrightarrow\) \(n\) \(=\) \(n\) \(div\) \(10^k\) (div là phép chia lấy nguyên)
-
Từ đó
Ta muốn lấy chữ số hàng đơn vị thì in ra \(n\) \(mod\) \(10\)
Ta muốn lấy chữ số hàng chục thì in ra \(\lfloor\frac{n}{10}\rfloor\) \(mod\) \(10\)
Approach 2
- Biểu diễn số kiểu xâu \(s\), ta sẽ xuất 2 kí tự cuối cùng của \(s\)
Comments