포럼
문제 ICPC00273

M. Methodic Multiplication

설명

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 align* x + 0 &= x & x 0 &= 0

x + S(y) &= S(x + y) & x S(y) &= x y + x 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 align* x y &= S(S(0)) S(0) = S(S(0)) 0 + S(S(0))

&= 0 + S(S(0)) = S(0 + S(0)) = S(S(0 + 0)) = S(S(0)) 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)))
출력
S(S(S(S(S(S(0))))))
예제 2
입력
S(S(S(S(S(0)))))
0
출력
0
문제 정보

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

출처 ICPC NCPC 2020

평가 및 의견

M. Methodic Multiplication

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

Log in to rate problems.

개별 의견

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

풀이 제출

M. Methodic Multiplication

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