Skip to content

Commit

Permalink
Update 055.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Dec 20, 2021
1 parent ca20465 commit c8fac9d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion 055.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main()
## 解答 2 (定数倍高速化)
この問題における mod 演算は、[Barrett reduction](https://en.wikipedia.org/wiki/Barrett_reduction) というテクニックを使うことで、計算に時間がかかる `%` 演算子の使用を回避して定数倍高速化できます。AC Library の `atcoder::modint` ライブラリには Barrett reduction が実装されているため、それを利用するとコードも短くなり一石二鳥です。

なお、`atcoder::modint` は、「C++ 標準の整数型 → `atcoder::modint`」の変換に通常の `%` 演算を使うため、プログラム全体を通してこの変換回数を減らすよう設計しないと速度向上効果が出ません(かえって遅くなることもある)。次のように、入力された値を最初にすべて `atcoder::modint` に変換して格納し、以降で変換が発生しないようにします。
なお、`atcoder::modint` は、「C++ 標準の整数型 → `atcoder::modint`」の変換に通常の `%` 演算を使うため、プログラム全体を通してこの変換回数を減らすよう設計しないと速度向上効果が出ません(かえって遅くなることもあります)。次のように、入力された値を最初にすべて `atcoder::modint` に変換して格納し、以降で変換が発生しないようにします。
```cpp
#include <iostream>
#include <vector>
Expand Down

0 comments on commit c8fac9d

Please sign in to comment.