RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00374

Slon

Unrated 레이팅 미적용
난이도
1s
시간 제한
64MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

\(3^{rd}\) round, November \(28^{th}\) 2015
A student called Slon is very mischievous in school. He is always bored in class and he is always
making a mess. The teacher wanted to calm him down and “tame” him, so he has given him a difficult
mathematical problem.
The teacher gives Slon an arithmetic expression \(A\), the integer \(P\) and \(M\). Slon has to answer the
following question: “What is the minimal n\(on-ne\)gative value of variable \(x\) in expression \(A\) so that
the remainder of dividing \(A\) with \(M\) is equal to \(P\)?”. The solution will always exist.
Additionally, it will hold that, if we apply the laws of distribution on expression \(A\), variable \(x\) will
not multiply variable \(x\) (formally, the expression is a polynomial of the first degree in variable \(x\)).
Examples of valid expressions \(A\): \(5 + x\) ∗(\(3 + 2\)), \(x + 3\)\(x + 4\) ∗(\(5 + 3\) ∗(\(2 + x - 2\)\(x\))).
Examples of invalid expressions \(A\): 5 ∗(\(3 + x\) ∗(\(3 + x\))), \(x\) ∗(\(x + x\) ∗(\(1 + x\))).

제약
입력 형식

The first line of input contains the expression \(A\) (1 ⩽|\(A\)| ⩽100 000).
The second line of input contains two integers \(P\) (0 ⩽\(P\)\(M - 1\)) i \(M\) (1 ⩽\(M\) ⩽1 000 000).
The arithmetic expression A will only consists of characters +, -, *, (, ), x and digits from 0 to 9.
The brackets will always be paired, the operators +, - a\(nd * wi\)ll always be applied to exactly two
values (there will not be an expression (-5) or (4+-5)) and all multiplications will be explicit (there
will not be an expression 4(5) or 2(x)).

출력 형식

The first and only line of output must contain the minimal n\(on-ne\)gative value of variable \(x\).

예제 1
입력
5+3+x
9 10
20+3+x
0 5
3*(x+(x+4)*5)
1 7
출력
output
output
1
2
1
설명

Clarification of the first example: The remainder of dividing 5 + 3 + x with 10 for x = 0 is 8, and the
remainder of division for x = 1 is 9, which is the solution.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2015/2016 Contest 3

평가 및 의견

Slon

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Slon

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8