专栏文章

题解:CF2132B The Secret Number

CF2132B题解参与者 2已保存评论 2

文章操作

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

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

题意简化

有一个正整数 xx,然后给这个数末尾加上 kk00 得到 yy 。把 x+yx + y 的结果记为 nn,给你 nn,找出所有可能的 xx

思路

观察题目可得,因为 kk 的取值范围是 2k182 \leq k \leq 18,所以我们考虑枚举。
在题目中,因为y=x×10ky = x \times 10^k,那么 n=x+x×10kn = x + x \times 10 ^k,提取公因式。就得到了 n=(10k+1)xn = (10^k + 1) \cdot x,那么我们设 d=10k+1d = 10 ^ k + 1,于是当 dd 可以被 nn 整除时,就说明我们找到了 xx ,并将 n÷dn \div d 的结果放入一个数组中,再把这个数组重新排序一遍即可。

Code

思路再前面说了,所以就不加注释了
CPP
#include <bits/stdc++.h>

using namespace std;

namespace RealDream {
	typedef long long ll;
	typedef unsigned long long ull;
	int main() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout.tie(nullptr);
		
		vector<ll> pows{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000};
		
		int t;
		cin >> t;
		while (t--) {
			ll n;
			cin >> n;
			vector<ll> ans;
			
			for (int k = 1; k <= 18; k++) {
				ll d = pows[k] + 1;
				if (d > n) break;
				if (n % d == 0) ans.push_back(n / d);
			}
			
			sort(ans.begin(), ans.end());
			if (ans.empty()) {
				cout << 0 << endl;
			} else {
				cout << ans.size() << endl;
				for (ull i = 0; i < ans.size(); i++) {
					if (i > 0) cout << ' ';
					cout << ans[i];
				}
				cout << endl;
			}
		}
		return 0;
	}
};

int main() {
	RealDream::main();
	return 0;
}

评论

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

正在加载评论...