专栏文章

题解:CF2132B The Secret Number

CF2132B题解参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@mio68b3s
此快照首次捕获于
2025/12/02 14:02
3 个月前
此快照最后确认于
2025/12/02 14:02
3 个月前
查看原文

简要题意

对一个数 xx 进行操作,在其末尾加上若干个 00 变成数字 yy,最后令 n=x+yn=x+y。现给出 nn,请反解出所有可能的 xx

思路

注意到 n1018n\le10^{18},且 n=x+y=x+x×10k=x(10k+1)n=x+y=x+x\times10^k=x(10^k+1),那么 kk 最大至 1717。因此我们可以枚举可能的 kk,如果存在 x=n10k+1x=\frac{n}{10^k+1} 为整数则记录下,最后统一输出即可。
如果最后发现数组内无元素,代表无解,记得输出 00
CPP
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll t, n;
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n;
        ll a[1005], tot = 0; ll i = 11;
        while (n >= i)
        {
            if (n % i == 0) a[++tot] = n / i;
            i = (i - 1) * 10 + 1;
        }
        cout << tot << endl;
        if (tot == 0) continue;
        for (int j = tot; j >= 1; j--) cout << a[j] << " ";
        cout << endl;
    }
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...