Editorial for Hiệu lập phương
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.
Đầu tiên \(a^3-b^3 = (a - b)(a^2+ab+b^2)\). Để nó là số nguyên tố thì một trong hai nhân tử phải bằng 1.
- Nếu \(a=1\) thì đáp số là \(0\)
- Nếu \(a > 1\) thì \(a^2+ab+b^2 > 1\). Do đó \(a-b=1\), hay \(b = a - 1\). Như vậy ta chỉ cần kiểm tra xem \(a^3-b^3\) có phải là số nguyên tố với \(b = a - 1\). Để ý rằng số này chính là \(3a^2 - 3a + 1 < 10^{13}\) nên ta có thể sử dụng thuật toán kiểm tra số nguyên tố cơ bản.
Comments