CF1249C1.Good Numbers (easy version)

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The only difference between easy and hard versions is the maximum value of nn.

You are given a positive integer number nn. You really love good numbers so you want to find the smallest good number greater than or equal to nn.

The positive integer is called good if it can be represented as a sum of distinct powers of 33 (i.e. no duplicates of powers of 33 are allowed).

For example:

  • 3030 is a good number: 30=33+3130 = 3^3 + 3^1,
  • 11 is a good number: 1=301 = 3^0,
  • 1212 is a good number: 12=32+3112 = 3^2 + 3^1,
  • but 22 is not a good number: you can't represent it as a sum of distinct powers of 33 (2=30+302 = 3^0 + 3^0),
  • 1919 is not a good number: you can't represent it as a sum of distinct powers of 33 (for example, the representations 19=32+32+30=32+31+31+31+3019 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
  • 2020 is also not a good number: you can't represent it as a sum of distinct powers of 33 (for example, the representation 20=32+32+30+3020 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).

Note, that there exist other representations of 1919 and 2020 as sums of powers of 33 but none of them consists of distinct powers of 33.

For the given positive integer nn find such smallest mm (n≤mn \le m) that mm is a good number.

You have to answer qq independent queries.

简单版本与困难版本的唯一区别在于 nn 的最大值。

给你一个正整数 nn。你非常喜爱“好数”,因此你想找出大于等于 nn 的最小的好数。

若一个正整数能表示为若干互不相同的 33 的幂之和(即不允许重复使用同一个 33 的幂),则称其为好数。

例如:

  • 3030 是一个好数:30=33+3130 = 3^3 + 3^1,
  • 11 是一个好数:1=301 = 3^0,
  • 1212 是一个好数:12=32+3112 = 3^2 + 3^1,
  • 但 22 不是好数:无法将其表示为互不相同的 33 的幂之和(例如 2=30+302 = 3^0 + 3^0),
  • 1919 不是好数:无法将其表示为互不相同的 33 的幂之和(例如,表示式 19=32+32+30=32+31+31+31+3019 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 均不合法),
  • 2020 也不是好数:无法将其表示为互不相同的 33 的幂之和(例如,表示式 20=32+32+30+3020 = 3^2 + 3^2 + 3^0 + 3^0 不合法)。

注意:虽然 1919 和 2020 还存在其他以 33 的幂之和形式的表示,但其中没有任何一种由互不相同的 33 的幂构成。

对于给定的正整数 nn,请找出满足 n≤mn \le m 的最小的好数 mm。

你需要回答 qq 个相互独立的查询。

输入格式

The first line of the input contains one integer qq (1≤q≤5001 \le q \le 500) — the number of queries. Then qq queries follow.

The only line of the query contains one integer nn (1≤n≤1041 \le n \le 10^4).

输入的第一行包含一个整数 qq(1≤q≤5001 \le q \le 500),表示查询次数。随后是 qq 次查询。

每次查询仅有一行,包含一个整数 nn(1≤n≤1041 \le n \le 10^4)。

输出格式

For each query, print such smallest integer mm (where n≤mn \le m) that mm is a good number.

对于每个查询,输出满足条件的最小整数 mm(其中 n≤mn \le m),使得 mm 是一个“好数”。

输入输出样例

  • 输入#1

    7
    1
    2
    6
    13
    14
    3620
    10000

    输出#1

    1
    3
    9
    13
    27
    6561
    19683

输入解题思路,AI测评打分。不知道怎么写?

首页