【例题3-5 UVA

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

```cpp for (int i = 1;i <= n;i++) { 算出i是哪一个的生成元。 假设是y. 则ans[y] = min(ans[y],i); } ```

【错的次数】

在这里输入错的次数

【反思】

在这里输入反思

【代码】

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5;

int ans[N + 10];

int main()
{
	for (int i = 1; i <= N; i++)
	{
		int x = i,temp = i;
		while (x)
		{
			temp += x % 10;
			x /= 10;
		}
		if (temp <= N && (ans[temp] == 0 || ans[temp] > i))
			ans[temp] = i;
	}
	int T;
	scanf("%d", &T);
	while (T--)
	{
		int n;
		scanf("%d", &n);
		printf("%d
", ans[n]);
	}
	return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7648883.html