Codeforces Round #723 (Div. 2) B. I Hate 1111

题意:

给定一个数 n n n,判断是否可以由 11 , 111 , 1111 , 11111 , , , , , 11 , 111 , 1111 ,11111,,,,, 11,111,1111,11111相加而成。

比如 144 = 11 + 11 + 11 + 111 144=11+11+11+111 144=11+11+11+111

题解:

任意一个111…都可以由11和111组成,因为111111…= 11 ∗ 1 0 n − 2 + 11 ∗ 1 0 n − 4 + . . . 11*10^{n-2}+11*10^{n-4}+... 1110n2+1110n4+... 11 ∗ 1 0 n − 2 + 11 ∗ 1 0 n − 4 + . . . + 111 11*10^{n-2}+11*10^{n-4}+...+111 1110n2+1110n4+...+111。因此 n = 11 a + 111 b = 11 a + ( 11 ∗ 10 + 1 ) b = 11 ( a + 10 b ) + b n=11a+111b = 11a+(11*10+1)b=11(a+10b)+b n=11a+111b=11a+(1110+1)b=11(a+10b)+b

所以只需判断 n − ( n % 11 ) ∗ 111 n-(n\%11)*111 n(n%11)111能否整除11即可。

代码:

#pragma GCC diagnostic error "-std=c++11"
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<ctime>
#define iss ios::sync_with_stdio(false)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const int MAXN=2e5+5;
const int inf=0x3f3f3f3f;
bool check(int x)
{
    int b=x%11;
    x-=b*111;
    if(x>=0&&x%11==0) return true;
    else return false;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(check(n)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值