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

Popcount

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

의견: 0

설명

\(M\)iniature \(Al\)gebraic \(Na\)tural \(R\)elay (also called MALNAR) is the latest technological advancement in the
flourishing realm of small programmable devices. You can write your own programs for this device using
MalnarScript, an esoteric programming language with the following set of features:
• Input to the program is a single n\(on-ne\)gative integer strictly less than \(2^{N}\).
• Output of the program is a single n\(on-ne\)gative integer strictly less than \(2^{N}\).
• When programming in MalnarScript you can only use one \(N-bi\)t unsigned integer variable \(A\). At
the beginning of the program, this variable holds the input and its value at the end of the program
is considered to be the program’s output.
• The source code of MalnarScript must consist of at most \(K\) commands of the form A=<ex\(pr> wh\)ich
are executed in order and each of them must consist of at most a thousand characters. The
symb\(ol ca\)n either be a variable \(A\), or it can conform to the definition of symbol
, or it can (inside parentheses) represent a t\(wo-me\)mbered expression in which each operand conforms
to the sa\(me in\) the definition above represents a n\(on-ne\)gative decimal integer strictly less than \(2^{N}\),
while the symb\(ol erat\(or> ca\)n either be +, -, |, &, << or >> which (in order) represent the operations
of addition, subtraction, bitwise or, bitwise and, left shift and right shift.
Also the character A can appear at most 5 times in t\(he \(pr> sy\)mbol.
In the case of overflow or underflow when performing the operations of addition and subtraction, Malnar-
Script will perform those operations modulo \(2^{N}\). For example, when \(N = 3\) the expression (\(7 + 3\)) will
evaluate to 2 and the expression (\(2 - 5\)) will evaluate to 5 in MalnarScript.
The right side of the equation in each command evaluates into a single number which will then be stored
into \(A\). In order to evaluate the right hand side expression, MalnarScript first replaces each occurrence of
\(A\) with its current value. The calculation of expression then proceeds as it would in any mathematical
expression, i.e., the parentheses take precedence. Note that the priorities of operators (in term of operation
order) are irrelevant because the final result is completely defined by placement of parentheses.
Your task is to write a program which outputs a program in MalnarScript which calculates the number of
ones in a binary representation of the input value.

제약

Subtask
Score
Constraints
1
15
\(2 \le N \le 100\), \(K = N - 1\)
2
15
\(N = 500\), \(K = 128\)
3
35
\(1 \le N \le 40\), \(K = 7\)
4
45
\(100 \le N \le 500\), \(K = 10\)

입력 형식

The first line contains two integers \(N\) and \(K\) from the task description.

출력 형식

In the first line you should output the number of commands of the produced MalnarScript program.
In the remaining lines you should output the commands of the sought program. Each command must
be printed in a separate line and must satisfy the syntax of MalnarScript as described in the task
description.
It is important that there are no unnecessary empty lines or extra whitespace characters in the output.
Each line (including the last) must be terminated by the e\(nd-of-li\)ne character (’\n’).

예제 1
입력
2 2
출력
1
A=(A-((A&2)>>1))
예제 2
입력
3 5
출력
2
A=((A&4)|((A&3)-((A&2)>>1)))
A=((A&3)+((A&4)>>2))
설명

Clarification of the first example:
input = 0 ⇒output = (0 −((0&2) >> 1)) = (0 −(0 >> 1)) = (0 −0) = 0
input = 1 ⇒output = (1 −((1&2) >> 1)) = (1 −(0 >> 1)) = (1 −0) = 1
input = 2 ⇒output = (2 −((2&2) >> 1)) = (2 −(2 >> 1)) = (2 −1) = 1
input = 3 ⇒output = (3 −((3&2) >> 1)) = (3 −(2 >> 1)) = (3 −1) = 2

문제 정보

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

출처 COCI 2019/2020 Contest 2

평가 및 의견

Popcount

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

Log in to rate problems.

개별 의견

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

풀이 제출

Popcount

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