#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int m,n;
int SG[1000001];
int sg(int x)
{
	if(SG[x]!=-1) return SG[x];
	if(!x) return SG[x]=0;
	set<int>S;
	int maxv=0,minv=2147483647;
	int t=x;
	while(t)
	  {
	  	if(t%10)
	  	  {
	  	  	maxv=max(t%10,maxv);
	  	  	minv=min(t%10,minv);
	  	  }
	  	t/=10;
	  }
	S.insert(sg(x-maxv));
	S.insert(sg(x-minv));
	for(int i=0;;++i)
	  if(S.find(i)==S.end())
	    return SG[x]=i;
}
int main()
{
	scanf("%d",&m);
	memset(SG,-1,sizeof(SG));
	for(;m;--m)
	  {
	  	scanf("%d",&n);
	  	puts(sg(n)?"YES":"NO");
	  }
	return 0;
}

相关文章:

  • 2022-12-23
  • 2021-11-10
  • 2021-11-21
  • 2021-07-14
  • 2021-09-13
  • 2021-08-17
  • 2021-03-17
  • 2022-12-23
猜你喜欢
  • 2022-01-20
  • 2021-12-02
  • 2022-12-23
  • 2021-08-04
  • 2022-01-14
  • 2021-08-22
  • 2021-10-02
相关资源
相似解决方案