定理:a,b互质,则a,b最大不能表示出的数是ab-a-b
把这些11,111,1111数字拿出来看看,发现111111=111*100+111,…1111=11∗100+11,11111=111∗100+11,111111=111∗100+111,…
于是可以得出结论:只有11和111是我们必需的,其他的都可以不要。
于是问题转化成:
方程11x+111y=b是否有解(x,y).
又看到gcd(11,111)=1,这里很容易想到扩展欧几里得定理。
即已知a,b为大于1的正整数,gcd(a,b)=1,则使不定方程ax+by=C无负整数解的最大整数为C = a*b − a − b 。
#include<bits/stdc++.h>
using namespace std;
template <typename T> void debug(string s, T x) { cout << s << "=" << x << "\n"; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;
const ll N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 0x7fffffff;
int trans[15];
int vis[11*111];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
trans[1]=1;
for(int i=2;i<=4;i++){
trans[i]=trans[i-1]*10+1;
}
vis[0]=1;
for(int i=2;i<=4;i++){
for(int j=11;j<=11*111;j++){
if(!vis[j]){
if(j-trans[i]>=0){
if(vis[j-trans[i]])vis[j]=1;
}
}
}
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if(n>11*111-11-111)cout<<"YES\n";
else {
if(vis[n])cout<<"YES\n";
else cout<<"NO\n";
}
}
return 0;
}