Logo
(追記) (追記ここまで)

21059번 - Methodic Multiplication 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB16313811986.232%

문제

After one computer crash too many, Alonso has had enough of all this shoddy software and poorly written code! He decides that in order for this situation to improve, the glass house that is modern programming needs to be torn down and rebuilt from scratch using only completely formal axiomatic reasoning. As one of the first steps, he decides to implement arithmetic with natural numbers using the Peano axioms.

The Peano axioms (named after Italian mathematican Giuseppe Peano) are an axiomatic formalization of the arithmetic properties of the natural numbers. We have two symbols: the constant 0ドル,ドル and a unary successor function $S$. The natural numbers, starting at 0ドル,ドル are then 0ドル,ドル $S(0),ドル $S(S(0)),ドル $S(S(S(0))),ドル and so on. With these two symbols, the operations of addition and multiplication are defined inductively by the following axioms: for any natural numbers $x$ and $y,ドル we have \[ \begin{align*} x + 0 &= x & x \cdot 0 &= 0 \\ x + S(y) &= S(x + y) & x \cdot S(y) &= x \cdot y + x \end{align*} \] The two axioms on the left define addition, and the two on the right define multiplication.

For instance, given $x = S(S(0))$ and $y = S(0)$ we can repeatedly apply these axioms to derive \[ \begin{align*} x \cdot y &= S(S(0)) \cdot S(0) = S(S(0)) \cdot 0 + S(S(0))\\ &= 0 + S(S(0)) = S(0 + S(0)) = S(S(0 + 0)) = S(S(0)) \end{align*}\] Write a program which given two natural numbers $x$ and $y,ドル defined in Peano arithmetic, computes the product $x \cdot y$.

입력

The input consists of two lines. Each line contains a natural number defined in Peano arithmatic, using at most 1ドル,000円$ characters.

출력

Output the product of the two input numbers.

제한

예제 입력 1

S(S(0))
S(S(S(0)))

예제 출력 1

S(S(S(S(S(S(0))))))

예제 입력 2

S(S(S(S(S(0)))))
0

예제 출력 2

0

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2020 M번

  • 문제를 만든 사람: Per Austrin
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /