From 2c76b66c10c6e5ee8690d29e18d54be97faae1e2 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Fri, 21 Nov 2025 22:02:30 +0900 Subject: [PATCH] =?UTF-8?q?[20251121]=20BOJ=20/=20G3=20/=20=EB=82=98?= =?UTF-8?q?=EB=A8=B8=EC=A7=80=20=ED=95=A9=20/=20=EC=84=A4=EC=A7=84?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\247\200 \355\225\251.md\342\200\216" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "Seol-JY/202511/21 BOJ G3 \353\202\230\353\250\270\354\247\200 \355\225\251.md\342\200\216" diff --git "a/Seol-JY/202511/21 BOJ G3 \353\202\230\353\250\270\354\247\200 \355\225\251.md\342\200\216" "b/Seol-JY/202511/21 BOJ G3 \353\202\230\353\250\270\354\247\200 \355\225\251.md\342\200\216" new file mode 100644 index 00000000..1ffbbd49 --- /dev/null +++ "b/Seol-JY/202511/21 BOJ G3 \353\202\230\353\250\270\354\247\200 \355\225\251.md\342\200\216" @@ -0,0 +1,34 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + + long[] count = new long[M]; + count[0] = 1; + + long prefixSum = 0; + st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < N; i++) { + prefixSum += Long.parseLong(st.nextToken()); + int mod = (int) (prefixSum % M); + count[mod]++; + } + + long answer = 0; + for (int i = 0; i < M; i++) { + answer += count[i] * (count[i] - 1) / 2; + } + + System.out.println(answer); + } +} + +```