1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ABC304 F Shift Table~負数の剰余~

Last updated at Posted at 2023-06-11

はじめに

ABC304のFを公式解説を見ながら実装したがWAを取れなかった.
image.png

理由

答えが負の数になる場合, %=では負の数が返ってくるためMOD=998244353を足す必要があった.
公式解説ではmodintを使用しており内部で処理されていたと考えられる.

Qiita:【C++】負の数を正の数で割ったときの余りを求める
C++リファレンス:整数に対する除算と剰余算の丸め結果を規定C++11
C/C++で負の数の剰余は負になる

修正と結果

出力部分

cout << ans << endl;

を以下に変更.

MOD = 998244353;
cout << (ans + MOD) % MOD << endl;

結果AC!
image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?