Codeforces Round #723 (Div. 2) B. I Hate 1111--数论,dp

13 篇文章 0 订阅
11 篇文章 0 订阅

定理: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;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值