0分求调
查看原帖
0分求调
1098567
qw135797531楼主2025/7/30 10:08
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int N = 20;
bool t[N], cnt;
string b[N];
ull fun(ull a, string b)
{
	int l2 = b.size();
	ull d = 0;
	for (int i = 0; i < l2; i ++)
	{
		int e = int(b[i] - 48);
		d = d * 10 + e;
	}
	ull res = a - d;
	return res;
}
bool check(string a, int k)
{
	int l1 = a.size();
	l1 ++;
	if (l1 % k == 0) return true;
	return false;
}
void init()
{
	for (int i = 1; i <= 18; i ++)
	{
		string cnt = "";
		for (int j = 1; j <= i; j ++)
			cnt += '9';
		b[i] = cnt;
	}
}
bool dfs(int k, ull n)
{
	if (n == 0) return true;
	if (n < 0) return false;
	for (int i = 0; i <= 18; i ++)
	{
		if (check(b[i], k))
			if (dfs(k, fun(n, b[i])))
				return true;
	}
	return false;
}
int main()
{
	int t;
	cin >> t;
	init();
	while(t --)
	{
		int k;
		ull n;
		cin >> k >> n;
		if (dfs(k, n))
			puts("aya");
		else
			puts("baka");
	}
}
2025/7/30 10:08
加载中...