Editorial for Exponential problem


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.

Subtask 1

\(a,m\) khá bé nên ta có thể thực hiện như sau:

  • Tính trước các giá trị \(F_1 = a^1,F_2 = a^2, ..., F_m = a^m\) (có thể dùng hàm pow, lũy thừa nhị phân, hoặc chạy for, v.v)
  • Sau đó duyệt từ \(1\) đến \(m\) và nhân dồn vào biến kết quả: result = (result * f[i]) % (1e9 + 7)

Độ phức tạp của subtask là \(\Theta(t\times m)\)

Subtask 2

  • Ta nhận thấy rằng: \(a^1 \times a^2 \times ... \times a^m = a^{1+2+...+m}\)
  • Ở subtask này ta bắt buộc phải dùng lũy thừa nhị phân thì mới \(AC\) được. Vậy ta sẽ tính trước giá trị \(W=1+2+...+m=m \times \frac{m+1}{2}\) rồi tính \(X=a^{W} \% (10^9+7)\). Đến đây thì ta nhận thấy đây là một bài sử dụng lũy thừa nhị phân cơ bản. Có thể tham khảo bài Module 2 để thực hiện phần này trong \(\Theta (\log (m))\)

Độ phức tạp của subtask này là \(\Theta (t \times \log (m))\)



Comments

There are no comments at the moment.