CF1249C2.Good Numbers (hard version)
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
- 30 is a good number: 30=33+31,
- 1 is a good number: 1=30,
- 12 is a good number: 12=32+31,
- but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2=30+30),
- 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19=32+32+30=32+31+31+31+30 are invalid),
- 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20=32+32+30+30 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n≤m) that m is a good number.
You have to answer q independent queries.
简单版本与困难版本的唯一区别在于 n 的最大值。
给你一个正整数 n。你非常喜欢“好”的数,因此你想找到大于等于 n 的最小的“好”数。
若一个正整数能表示为若干互不相同的 3 的幂之和(即不允许重复使用同一个 3 的幂),则称其为“好”数。
例如:
- 30 是一个好数:30=33+31,
- 1 是一个好数:1=30,
- 12 是一个好数:12=32+31,
- 但 2 不是好数:你无法将其表示为互不相同的 3 的幂之和(例如 2=30+30),
- 19 不是好数:你无法将其表示为互不相同的 3 的幂之和(例如表示式 19=32+32+30=32+31+31+31+30 均不合法),
- 20 也不是好数:你无法将其表示为互不相同的 3 的幂之和(例如表示式 20=32+32+30+30 不合法)。
注意:19 和 20 存在其他表示为 3 的幂之和的方式,但其中均不满足所有幂互不相同这一条件。
对于给定的正整数 n,请找出满足 n≤m 的最小的 m,使得 m 是一个好数。
你需要回答 q 个相互独立的查询。
输入格式
The first line of the input contains one integer q (1≤q≤500) — the number of queries. Then q queries follow.
The only line of the query contains one integer n (1≤n≤1018).
输入的第一行包含一个整数 q(1≤q≤500),表示查询次数。随后是 q 次查询。
每次查询仅包含一行,其中有一个整数 n(1≤n≤1018)。
输出格式
For each query, print such smallest integer m (where n≤m) that m is a good number.
对于每个查询,输出满足条件的最小整数 m(其中 n≤m),使得 m 是一个“好数”。
输入输出样例
输入#1
8 1 2 6 13 14 3620 10000 1000000000000000000
输出#1
1 3 9 13 27 6561 19683 1350851717672992089
输入解题思路,AI测评打分。不知道怎么写?