From 7c8904ff510a85a58c6ee2d1316eefdf148a6c15 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Wed, 1 Nov 2023 17:29:03 +0800 Subject: [PATCH] fix: overflow in LeftMove --- src/int2048.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/int2048.cpp b/src/int2048.cpp index dc2765f..e46f857 100644 --- a/src/int2048.cpp +++ b/src/int2048.cpp @@ -398,7 +398,8 @@ void int2048::LeftMoveBy(int L) { this->num_length += big_move * int2048::kNum; if (small_move == 0) return; for (int i = this->buf_length - 1; i >= 0; i--) { - (this->val[i] *= kPow10[small_move]) %= int2048::kStoreBase; + this->val[i] = + ((long long)this->val[i] * kPow10[small_move]) % int2048::kStoreBase; if (i - 1 >= 0) { this->val[i] += this->val[i - 1] / kPow10[int2048::kNum - small_move]; }