题意:
给定一个数 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}+... 11∗10n−2+11∗10n−4+...或 11 ∗ 1 0 n − 2 + 11 ∗ 1 0 n − 4 + . . . + 111 11*10^{n-2}+11*10^{n-4}+...+111 11∗10n−2+11∗10n−4+...+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+(11∗10+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;
}
}