問題一覧 > 通常問題

No.1092 modular arithmetic

レベル : / AI推定難易度 : 600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 114
作問者 : null / テスター : butsurizuki
お気に入りにしたユーザー ProblemId : 4569 / 自分の提出
問題文最終更新日: 2026-10-16 19:42:54
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original

Problem Statement

You are given a prime $P$, $N$ non-negative integers $A_i(1 \le i \le N)$, and a string $S$ consisting of $N - 1$ characters, each of which is one of ```+```, ```-```, ```*```, ```/```.
Letting $operator_j$ be the $j(1 \le j \le N - 1)$-th character of $S$, compute and output the following value.
$(( \dots ((A_1\ operator_1\ A_2)\ operator_2\ A_3)\ operator_3 \dots \ A_{N-1})\ operator_{N-1}\ A_N)$ over $\mod P$
In other words, perform the calculation in order from the front, regardless of the operators.
Here, the division p/q over $\mod P$ is defined to have as its result the unique integer $r$ such that $p \equiv qr (\mod P)$ and $0 \le r < P$.

Input

$P\ N$
$A_1\ A_2\ \dots\ A_N$
$S$

$2 \le P \le 10^9$
$2 \le N \le 10^5$
$P$ is prime
$1 \le A_i < P$
$|S| = N - 1$
$S$ consists only of +, -, *, /

Output

Output the answer on one line. End the output with a newline.

Sample

Sample 1
Input
11 10
1 5 5 2 3 4 6 5 2 8
++*--//*-
Output
4

Compute
$((((1+5+5) \times 2-3-4)/6)/5) \times 2-8$
over $\mod 11$. For readability, parentheses that do not change the meaning have been omitted.

Source

YSF Beginner Contest: E - modular arithmetic
writer: null
tester: butsuri_0523
Ported in accordance with HackerRank's terms. Some parts have been modified due to site-specific reasons, among others.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。