G - Power Expression Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 66

注意

この問題に対する言及は、2021/7/17 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

正整数 NN を、相異なる 33 べきの和差で表してください。

形式的には、以下の条件をすべて満たす数列 AA を構築してください。

  • AA の長さを MM として、1M1001 \leq M \leq 100
  • i=1MAi=N\sum_{i=1}^{M}A_i = N
  • Ai1018|A_i| \leq 10^{18}
  • i (1iM)i\ (1 \leq i \leq M) について、Ai|A_i|33 べき。即ち、ある非負整数 xx を用いて Ai=3x|A_i|=3^x と表すことができる。
  • AiAj (ij)|A_i| \neq |A_j|\ (i \neq j)

この問題の制約下で、このような数列 AA の存在は保証されます。

制約

  • 1N10151 \leq N \leq 10^{15}
  • NN は整数

入力

入力は以下の形式で標準入力から与えられる。

NN

出力

以下の形式で問題文中の条件を満たす数列 AA を出力せよ。問題文同様、MMAA の長さを表す。

MM
A1A_1 A2A_2 \ldots AMA_M

条件を満たす AA が複数存在する場合、そのいずれを出力してもよい。


入力例 1Copy

Copy
6

出力例 1Copy

Copy
2
9 -3 

9933 は共に 33 べきであり、また 9+(3)=69+(-3)=6 であるため、この出力は問題文中の条件を満たします。


入力例 2Copy

Copy
9193

出力例 2Copy

Copy
9
2187 27 1 -243 3 9 -81 6561 729 

入力例 3Copy

Copy
10120190919012

出力例 3Copy

Copy
16
-1594323 9 -177147 -531441 1162261467 -4782969 387420489 -6561 -2187 2541865828329 -27 7625597484987 3486784401 10460353203 -94143178827 31381059609 

入力が 3232 bit 整数型に収まりきらない場合があります。

Score : 66 points

Warning

Do not make any mention of this problem until July 17, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Represent a positive integer NN by additions and subtractions of distinct powers of 33.

Formally, construct a sequence AA that satisfies all of the following conditions.

  • 1M1001 \leq M \leq 100, where MM is the length of AA.
  • i=1MAi=N\sum_{i=1}^{M}A_i = N.
  • Ai1018|A_i| \leq 10^{18}.
  • For each i (1iM)i\ (1 \leq i \leq M), Ai|A_i| is a power of 33. That is, there is a non-negative integer xx such that Ai=3x|A_i|=3^x.
  • AiAj (ij)|A_i| \neq |A_j|\ (i \neq j).

It is guaranteed that such a sequence AA exists under the Constraints of this problem.

Constraints

  • 1N10151 \leq N \leq 10^{15}
  • NN is an integer.

Input

Input is given from Standard Input in the following format:

NN

Output

Print a sequence AA that satisfies the conditions in the Problem Statement in the format below, where MM again denotes the length of AA.

MM
A1A_1 A2A_2 \ldots AMA_M

If there are multiple sequences AA satisfying the conditions, you may print any of them.


Sample Input 1Copy

Copy
6

Sample Output 1Copy

Copy
2
9 -3 

Both 99 and 33 are powers of 33, and we have 9+(3)=69+(-3)=6, so this output satisfies the conditions.


Sample Input 2Copy

Copy
9193

Sample Output 2Copy

Copy
9
2187 27 1 -243 3 9 -81 6561 729 

Sample Input 3Copy

Copy
10120190919012

Sample Output 3Copy

Copy
16
-1594323 9 -177147 -531441 1162261467 -4782969 387420489 -6561 -2187 2541865828329 -27 7625597484987 3486784401 10460353203 -94143178827 31381059609 

Input may not fit into a 3232-bit integer type.



2025-04-24 (Thu)
04:04:48 +00:00