You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times).
For instance,
33=11+11+11
144=111+11+11+11
Input
The first line of input contains a single integer t (1 ≤ t ≤ 10000) — the number of testcases.
The first and only line of each testcase contains a single integer x (1 ≤ x ≤ 10^9) — the number you have to make.
Output
For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO".
You can print each letter of "YES" and "NO" in any case (upper or lower).
Example
Input
3
33
144
69
Output
YES
YES
NO
Note
Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to determine if a given positive integer x (1 ≤ x ≤ 1e9) can be expressed as a sum of numbers from the set S = {11, 111, 1111, 11111, ...}, i.e., numbers that consist of all ones (repunits) of length at least 2 (since 1 is not included? Actually 1 is not included because they say 11, 111, 1111, ... So the smallest is 11). The repunits: R_n for n>=2, where R_n = (10^n - 1)/9.
We can use each any number of times.
Given constraints: t up to 10000, x up to 1e9. We need an O(1) or O(log x) per test.
This is a classic coin problem with infinite supply of certain denominations. We need to check feasibility: is x representable as a non-negative integer combination of numbers 11, 111, 1111, ...?
Observation: Since 1111 = 101 * 11? Actually 1111 = 101 * 11? Let's check: 11 * 101 = 1111, yes. So 1111 is a multiple of 11. Similarly, 11111? 11111 / 11 = 1010.0909? Actually 11 * 1010 = 11110, not 11111. Let's compute: 11111 / 11 = 1010.0909, not integer. But check if any repunit is divisible by 11: a number with even number of ones is divisible by 11. For repunit with n ones: R_n is divisible by 11 if n is even. Because the alternating sum of digits: for even n, there are equal number of ones in odd and even positions, so divisible by 11. Indeed R_{2k} = (10^{2k}-1)/9 = (10^{2}-1)/9 * something? Actually known: R_{2k} = 11 * R_{2k} / 11? For k=1, R_2=11 divisible by 11. For k=2, R_4=1111=10111? Yes, 1111/11=101. So any even-length repunit is a multiple of 11. Odd-length repunits (>1) are not multiples of 11 generally. For n=3: 111 = 337, not divisible by 11. So the set S contains 11 (the smallest) and all other repunits. But note that any repunit with even number of digits is a multiple of 11, so they are redundant if we already have 11 because we could use multiple 11's to sum to that multiple. However, odd-length repunits greater than 11 (like 111, 11111, 1111111, etc.) are not multiples of 11, but they might help represent numbers that are not multiples of 11 alone.
But we also have 111, 11111, etc. However, we can also combine 11 and 111 to make many numbers.
We need to determine if for given x, there exist nonnegative integers a, b, c, ... such that x = 11a + 111b + 1111c + ... But since 1111, 111111, etc are multiples of 11, they don't add anything beyond multiples of 11. Actually 1111 = 101 * 11, so using 1111 is equivalent to using 11 101 times. Similarly, any even-length repunit is multiple of 11, so they don't help to represent numbers not divisible by 11. So the only odd-length repunits (length ≥ 3) are the ones not divisible by 11. Among those, the smallest is 111 = 3 * 37. Next is 11111 (5 ones), 1111111 (7), etc.
But are these larger odd-length repunits needed? Since we have 111, perhaps any number that is representable using larger odd repunits can also be represented using only 11 and 111? We need to check. Because 11111 = 111100 + 11? Actually 111100 = 11100, not 11111. But we can combine 111 and 11. 11111 = 111100 + 11? No, 111100 = 11100, plus 11 = 11111, yes that works! 11100+11=11111, but careful: 111100 means using 111 hundred times? But we are allowed to use 111 any number of times, so we can use 111 repeated 100 times and 11 once: that would sum to 11111. So indeed 11111 = 111100 + 11, so it's representable by 111 and 11. But wait, the coefficient 100 is an integer, yes we can use 111 up to 100 times, that's allowed. So 11111 is not necessary. Similarly, any larger odd repunit: for length L odd (≥5), we can express R_L = R_{L-2} * 100 + 11? Let's check: R_{L} = (10^L -1)/9. R_{L-2} = (10^{L-2}-1)/9. Then R_{L-2}100 = (10^{L-2}-1)/9 * 100 = (10010^{L-2} - 100)/9 = (10^L - 100)/9. Adding 11 gives (10^L - 100)/9 + 11 = (10^L - 100 + 99)/9 = (10^L - 1)/9 = R_L. Yes, because 11 = 99/9? Actually 11 = 99/9. So indeed, R_L = 100R_{L-2} + 11. So by induction, any repunit of odd length ≥3 can be expressed using 111 and 11? Starting from R_3 = 111, then R_5 = 100111 + 11, R_7 = 100R_5 + 11, etc. So indeed, all larger odd repunits are linear combinations of 111 and 11. So the set S essentially generates the same semigroup as {11, 111}. Because all even-length repunits are multiples of 11, so they are in the semigroup generated by 11 alone. And all odd-length repunits >111 are combinations of 11 and 111 as shown. Therefore, the problem reduces to: Can x be expressed as 11a + 111*b for nonnegative integers a, b? (Since we can use 11 any number of times, and 111 any number of times). But wait: what about using multiple copies of 111 and 11? Yes.
Thus, we need to check if x ∈ {11a + 111b : a,b ∈ ℕ0}.
But is it sufficient? Let's confirm: Could there be a representation that uses e.g., 1111 but yields something that cannot be represented as just 11 and 111? Since 1111 = 10111, that's equivalent to a=101, b=0, so it's covered. Similarly, 11111 = 100111 + 11, that's a=1, b=100. So indeed any combination using any repunits can be converted to a combination of 11 and 111. So yes, the semigroup is exactly the set of nonnegative integer combinations of 11 and 111.
Thus the problem: given x, does there exist nonnegative integers a,b such that 11a + 111b = x.
Now 111 is relatively large. Since 111 = 3*37.
We need to decide feasibility quickly.
Observation: Since gcd(11,111)=? Compute gcd(11,111). 111 = 337, 11 is prime, so gcd=1? 11 does not divide 111, and 111 mod 11 = 111 - 1110=111-110=1, so gcd=1. Indeed gcd(11,111)=1. So by the Chicken McNugget theorem, every sufficiently large integer can be expressed as 11a+111b for nonnegative integers a,b. The Frobenius number for two coprime numbers m,n is mn - m - n = 11111 - 11 - 111 = 1221 - 122 = 1099? Actually 11111=1221, minus 11 minus 111 = 1221-122=1099. So all integers > 1099 are representable. Also, we need to check representability for x up to 10^9, so for x > 1099 we can simply answer YES. Wait: But is that unconditional? The Chicken McNugget theorem says that for two coprime positive integers a,b, the largest integer that cannot be expressed as nonnegative combination is ab - a - b = 1099. So any integer >= 1100 is representable. However, we must check that 0 is representable? Not needed. So for x > 1099, we answer YES.
But careful: The theorem holds for two numbers that are coprime. 11 and 111 are coprime, yes. So for x ≥ 1100, it's representable. However, we need to consider if we are restricted to only 11 and 111? But we earlier argued that using other repunits doesn't extend the set beyond 11 and 111 combinations. So the set of representable numbers is exactly the semigroup generated by 11 and 111. Since gcd=1, it's all sufficiently large integers. So for x >= 1100, answer YES.
But is that bound correct? Let's test a few numbers: 1099? 11*? 1099 mod 11 = 1099-1199=1099-1089=10, so not representable if we rely only on 11a+111b? But maybe using 1111 etc could represent 1099 differently? But we argued that those are redundant. Let's test if 1099 is representable: We need 11a+111b=1099. Since 111 mod 11 = 1, we can write 1099 mod 11 = (1099 mod 11) = 10. But 111b mod 11 = b mod 11 (since 111 ≡ 1 mod 11). So we need b ≡ 10 mod 11, i.e., b = 10,21,32,... The smallest b=10 gives 11110=1110, which is >1099. So no representation. b= -? no. So 1099 is not representable. Using 1111? 1111 is >1099, so not. Using other repunits? 11111 > 1099, so no. So 1099 is indeed not representable. So bound 1100 works.
But wait: What about numbers like 1100? 1100 mod 11 = 0? 11100=1100. So yes. 1101? 1101 mod 11 = 1? Since 11100=1100, remainder 1. Need b such that b mod 11 = 1. b=1 gives 111, then 1101-111=990, which is 1190, so a=90 => 1190=990, sum=990+111=1101, works. So yes.
Thus for x > 1099, answer YES.
Now for x ≤ 1099, we need to check manually. Since t up to 10000, and x up to 1e9, but we only need to do special handling for x ≤ 1099. We can either precompute all representable numbers up to 1099 via DP or simple math. Since the numbers are small, we can loop over b from 0 to floor(1099/111)=9, compute a = (x - 111*b)/11 and check integer and >=0.
Alternatively, we can use the fact that since 111 ≡ 1 mod 11, the condition is: there exists nonnegative b such that x - 111b is nonnegative and divisible by 11. For given x, we can try b from 0 to while 111b <= x, but since x ≤ 1099, b up to 9 is sufficient. That's constant.
But we can also derive a necessary and sufficient condition for any x: Since 111 ≡ 1 mod 11, the set of residues mod 11 achievable by 111b is all residues because as b runs from 0 to 10 we get each residue mod 11 exactly once (since 111 ≡ 1, b mod 11 gives the residue). So if we can find b such that b ≤ floor(x/111) and also (x - 111b) divisible by 11, then YES. For x large, there will always be such b because for x ≥ 11110 = 1110? Actually we need to ensure that among b = 0,...,10, at least one satisfies 111b ≤ x. For x ≥ 1110, that's true. But Frobenius bound says 1100 is enough, but 1110 is larger. Actually 11110 = 1110 > 1099, so the bound from Chicken McNugget is tighter because you can have combination with b up to 10? Wait, consider x=1100, b from 0..10: we need b such that 111b ≤ 1100 and x-111b divisible by 11. b=10 gives 1110 >1100, not allowed. But we found representation with b=0? Actually for 1100, b=0 works because it's multiple of 11. So we don't need b=10. For x=1101, b=1 works (111≤1101). So for x up to 1099, the maximum b needed could be up to 9 (since 111*9=999). But some numbers might require b=10? Let's check if any number between 1000 and 1099 may require b=10? b=10 yields 1110 > x, so not allowed. So indeed b up to 9. So checking up to b=9 is enough for x≤1099. So simple brute force per test for x ≤ 1099 works.
Thus overall solution: For each test case with integer x, if x >= 1100: output "YES". Else (x < 1100): check if there exists b from 0 to floor(x/111) such that (x - 111*b) % 11 == 0. If yes, output "YES", else "NO".
But we must also consider that x may be less than 11? The smallest denomination is 11, so if x < 11, then can't be represented (except maybe using zero? But need positive sum? The problem: "summing up some number of 11, 111, ..." Usually at least one number? The statement "some number of" could be zero? But generally at least one. However, if x=0 not given because x>=1. So for x from 1 to 10, answer NO. Our brute force will handle: for x<11, floor(x/111)=0, then we check if x % 11 ==0? But x is less than 11, x%11==x, so only x=0 would satisfy, but x>=1 so none. So it yields NO. Good.
Edge cases: x=11 => YES (b=0). x=111 => YES (b=1). x=22 => YES (b=0). x=122? 122 -111=11 => b=1 works. So YES. x=1099 we said NO.
But is there any nuance? Could there be representation using e.g., 1111 (which is 101*11) that yields a number > 1099 but that might be representable as 11a+111b? Already covered. So our logic is sound.
But we must be cautious: The Chicken McNugget theorem says that the largest integer not representable is 11*111 - 11 - 111 = 1099. Since they are coprime, all integers greater than 1099 are representable. But we must ensure that the condition of nonnegative a,b is exactly the semigroup we consider. Yes.
Thus algorithm is simple.
But wait: Are there any other repunits like 1111111111 (10 ones) which is multiple of 11, but maybe using them might allow representation for numbers > 1099 even if 11 and 111 alone cannot? No, because if x > 1099, it is representable by 11 and 111 alone. So adding more numbers doesn't harm.
Hence answer is straightforward.
But let's double-check with examples: Input 33, x=33, less than 1100. b max = floor(33/111)=0, so only b=0, 33%11=0? 33/11=3, yes, so YES. 144: floor(144/111)=1, b=0: 144%11=144-1113=144-143=1 not 0; b=1: 144-111=33, 33%11=0 => YES. 69: floor(69/111)=0, only b=0, 69%11=3? Actually 116=66, remainder 3, so NO. Output matches.
Now think about potential pitfalls: The Frobenius number is 1099. Check 1100 is representable? 11100=1100 => yes. 1099? Not. So threshold 1100 works. But is 1100 indeed representable? 11100, yes. 1101 we saw yes. So all x >=1100 should be YES. However, need to consider that 111 might not be the only odd repunit, but the reasoning holds. But what about numbers that are less than 1100 but require more than 9 b? For x=1090, let's test: b from 0 to 9. b=0: 1090%11? 1199=1089, remainder 1 => not. b=1: 1090-111=979, 979%11? 1189=979, yes 11*89=979 => works, so YES. So many numbers work. The only ones not are those with no b such that condition holds.
We could also derive an alternative condition: Since 111 ≡ 1 (mod 11), the condition is that there exists b with 0 ≤ b ≤ floor(x/111) and x ≡ b (mod 11). So we need to find b in [0, min(floor(x/111),10)] such that b ≡ x (mod 11). Actually b mod 11 should equal x mod 11. Because x - 111b ≡ x - b (mod 11) since 111≡1, we want that ≡0 mod 11, so b ≡ x (mod 11). So we need some b in [0, floor(x/111)] that is congruent to x mod 11. For x >= 1100, floor(x/111) >= 10? Actually for x=1100, floor(1100/111)=9, because 1119=999, 11110=1110 >1100. So floor=9. That's less than 10. But x=1100 mod 11 = 0. So we need b ≡ 0 mod 11, i.e., b = 0,11,... Within floor=9, only b=0 works, and b=0 ≤ 9 and gives representation. So it's okay. For x=1101, floor=9, x mod 11 = 1, need b ≡ 1 mod 11 => b=1 works. For x=1102, need b=2, works up to 9. Up to x=1109: floor(1109/111)=9, need b= (x mod 11). For 1109 mod 11: 11100=1100 remainder 9 => need b=9, works because 9 ≤ 9. So 1109 works. For x=1110, floor=10, x mod 11 = 1110 mod 11 = 1110-11100=1110-1100=10, need b ≡ 10 mod 11 => b=10 works because floor=10. So 1110 works. So all x>=1100? Wait, 1100 to 1109 all work as we saw. So 1100-1109 all work. 1099 fails because floor(1099/111)=9, x mod 11 = 10, need b=10 but b max=9, so fails. So threshold is indeed 1100.
But is 1099 the only exception below 1100? We need to confirm that there may be other numbers less than 1100 that are not representable. For example, maybe 1098? Check: 1098 mod 11 = 1098-1199=1098-1089=9, need b=9, 1119=999 <=1098, so b=9 works? Then remainder = 1098-999=99, which is 119, so a=9, works. So YES. So many are representable. So only those with x mod 11 = r such that the smallest nonnegative b ≡ r mod 11 is > floor(x/111) will be not representable. The smallest such b is r if r ≤ 10, or if r=0 then b=0, else b = r (since 0 ≤ r ≤ 10). So condition for NO is: floor(x/111) < (x mod 11). Because we need b = x mod 11 (or b = x mod 11 + 11k, but the smallest candidate is r = x mod 11). Since b must be at least r, and b = r is the smallest possible that matches the congruence. If r > floor(x/111), then no b exists. But is it possible that a larger b congruent to r mod 11 (i.e., r+11) could be ≤ floor(x/111)? For x < 1100, floor(x/111) is at most 9, so if r > floor, then r+11 would be at least r+11 > floor+11 > floor, so not possible. So indeed condition is exactly: if x mod 11 * 111 <= x? Not exactly: we need b = r such that 111r ≤ x? Since if b = r, then 111r must be ≤ x. But if 111r ≤ x, then floor(x/111) >= r, because floor(x/111) >= r if 111r ≤ x. So condition for YES is: 111 * (x mod 11) ≤ x. Because then we can take b = r and a = (x - 111r)/11. Conversely, if 111 * (x mod 11) > x, then no solution. However, is this condition sufficient? Check x=1099: x mod 11 = 10, 11110=1110 > 1099, so fails. x=1090: r=1? Actually 1090 mod 11 = 1? Let's compute: 1199=1089, remainder 1, so r=1. 1111=111 ≤ 1090, so condition says YES. Indeed we found representation. x=33: r=0, 1110=0 ≤33, YES. x=144: r=1? 144 mod 11 = 1? 1113=143 remainder 1, yes. 1111=111 ≤144, YES. x=69: r=3? 69 mod 11 = 3 (since 116=66 remainder 3). 111*3=333 >69, so NO.
Thus for x < 1100, we can simply check if 111 * (x % 11) ≤ x. But careful: what if x mod 11 = 0? Then condition is trivially true (since 0 ≤ x). So multiples of 11 are always representable (using only 11s). That's correct.
But does this condition cover all representable numbers? Let's test some borderline: x=110? 110 mod 11 = 0, so YES (1110). x=221? 221 mod 11: 1120=220 remainder 1, r=1, 1111=111 ≤221, so YES: 221-111=110, 110/11=10 -> 1110+111=221. Good. x=222? mod 11 = 2 (since 1120=220 remainder 2), 1112=222 ≤222, so YES: b=2, a=0? Actually x - 2111 = 0, a=0, works. So YES. x=223? mod 11=3, 1113=333 >223, condition says NO. But could we use b=14? b=14 gives 111*14=1554 >223, no. Could we use b=3? that's > floor? Actually floor(223/111)=2, so b max 2. b=2 gives remainder 223-222=1, not divisible by 11. b=1 gives 112, not divisible by 11. b=0 gives 223 mod 11=3, not divisible. So NO. Good.
Thus condition is sufficient.
But wait: For x < 1100, floor(x/111) ≤ 9, and r is between 0 and 10. So condition fails exactly when r > floor(x/111). Since floor(x/111) = ⌊x/111⌋, and note that 111 * r > x implies r > x/111, which is equivalent to r > floor(x/111) because r is integer. So condition is exactly r > floor(x/111). So we can compute that.
But note that for x >= 1100, the condition may also hold? Let's test x=1100: r=0, condition holds trivially. So it would say YES, which is correct. For x=1101: r=1, 1111=111 ≤1101, condition says YES. For x=1109: r=9, 1119=999 ≤1109, YES. For x=1110: r=10, 11110=1110 ≤1110, YES. For x=1111: r=0? 1111 mod 11 = 1111-11101=0, so YES. So for x>=1100, condition 111 * (x mod 11) ≤ x might also always be true? Let's check x=1099 which is <1100 fails. But what about a number slightly above 1099? Already all seem to satisfy. Could there be a number >1099 where r111 > x? For r=10, the condition requires x >= 1110. So for x between 1100 and 1109, r is at most 9, so 111r ≤ 999, which is ≤ x since x >=1100. So holds. For r=10, need x >=1110, which holds when x>=1110. So indeed for all x >= 1100, condition holds. Because worst case r=10 requires x≥1110, but for x between 1100 and 1109, r can't be 10 because if x is in that range, x mod 11 cannot be 10? Let's see: 1100 mod 11=0, 1101=1, 1102=2, ..., 1109=9, indeed 1100 to 1109 give residues 0-9. 1110 gives 10. So the only problematic residue 10 appears only when x ≥ 1110. And for x≥1110, condition is satisfied because 1110 ≤ x. So indeed for all x ≥ 1100, the condition holds. So we can simply use the condition for all x, without threshold, i.e., check if 111 * (x % 11) ≤ x. But wait: what about x=1099? 1099 mod 11 = 10, 1110 > 1099 -> false, so NO. So seems like a simple check: If x % 11 == 0 -> always YES. Else, let r = x % 11. If 111 * r <= x, then YES, else NO.
But is this condition both necessary and sufficient for all x? Let's test some small x: x=1 -> r=1, 111>1 -> NO. Good. x=11 -> r=0 -> YES. x=22 -> YES. x=33 -> YES. x=44 -> YES. x=55 -> YES. x=66 -> YES. x=77 -> YES. x=88 -> YES. x=99 -> YES. x=110 -> r=0 -> YES. x=121 -> r=0? 121 mod 11 = 0? 1111=121, yes, so YES. x=131? r=10? 1111=121 remainder 10, 11110=1110 >131, so condition says NO. Let's check if 131 is representable: try b=1: 131-111=20, not multiple of 11. b=0: 131 mod 11=10, not. So NO. Good. x=142? mod 11 = 10? 1112=132 remainder 10, 11110=1110 >142, condition says NO. Check: b=1: 142-111=31, not multiple of 11; b=0: 142 mod 11=10; b=2: 222 >142. So NO. x=153? mod 11 = 10? 1113=143 remainder 10? Actually 1113=143, remainder 10? 153-143=10, yes r=10, 1110>153 => NO. Check: b=1: 153-111=42, 42 not multiple of 11; b=0: 153 mod 11=10; so NO. x=164? 1114=154 remainder 10, same. So these numbers are not representable. But what about x=175? 11*15=165 remainder 10, still no. But eventually, x=220? 220 mod 11 = 0, yes. So condition seems correct.
But wait: Could there be a representation where b is not equal to r, but b = r + 11k, with k > 0, and still b ≤ floor(x/111)? For x small, floor(x/111) is small, so if r is large and not ≤ floor, maybe r+11 is still > floor. But for larger x, floor(x/111) may be large enough to accommodate r+11. But our condition only checks r111 ≤ x. But it might miss cases where r111 > x but (r+11)111 ≤ x? That would mean 111(r+11) ≤ x but 111r > x. Since 111(r+11) = 111r + 1221. If 111r > x, then adding 1221 would make it even larger, so cannot be ≤ x. Actually if 111r > x, then 111(r+11) = 111r + 1221 > x + 1221 > x. So impossible. Therefore, if the smallest b congruent to r (which is r) is too large to satisfy b ≤ floor(x/111), then any larger b congruent to r will be even larger and also exceed floor(x/111). Because floor(x/111) is less than r, and r+11 > r > floor, so no. So indeed the condition is necessary and sufficient: existence of b such that b ≡ r (mod 11) and b ≤ floor(x/111) is equivalent to r ≤ floor(x/111). That is exactly 111 * r ≤ x? Not exactly: r ≤ floor(x/111) implies 111r ≤ 111floor(x/111) ≤ x? Actually 111floor(x/111) ≤ x, but 111r ≤ 111floor(x/111) if r ≤ floor, but could be > x? Wait: if r ≤ floor(x/111), then 111r ≤ 111floor(x/111) ≤ x? Actually 111floor(x/111) is the largest multiple of 111 not exceeding x. Since floor(x/111) = q, then 111q ≤ x. If r ≤ q, then 111r ≤ 111q ≤ x. So indeed 111r ≤ x. Conversely, if 111r ≤ x, then r ≤ x/111, and since r is integer, r ≤ floor(x/111)? Not necessarily: floor(x/111) is the integer part of x/111. If 111r ≤ x, then r ≤ x/111. But floor(x/111) could be less than r? Actually if r ≤ x/111, then since floor(x/111) is the greatest integer ≤ x/111, we have floor(x/111) ≥ r? Not necessarily: Consider x=120, x/111 ≈1.081, floor=1. r=1, 1111=111 ≤120, r=1 ≤ floor=1, okay. If r=1, it's fine. But could we have r such that 111r ≤ x yet r > floor(x/111)? That would mean r ≤ x/111 but r > floor(x/111). However, floor(x/111) is the integer part, so any integer ≤ x/111 must be ≤ floor(x/111)? Actually if r is an integer and r ≤ x/111, then r ≤ floor(x/111) because floor(x/111) is the largest integer ≤ x/111. So r ≤ floor(x/111). So indeed 111r ≤ x implies r ≤ floor(x/111). Thus the condition "111r ≤ x" is equivalent to "r ≤ floor(x/111)". So it's exactly the same.
Thus for all x, the representation exists if and only if 111 * (x % 11) ≤ x.
But careful: This derivation assumed that b must be congruent to x mod 11, and the smallest such nonnegative b is r = x mod 11. But what about the case where x mod 11 = 0? Then r=0, condition holds trivially. Good.
Now, does this condition work for x=0? Not needed. For x from 1 to 10, r = x, 111*r > x, so NO, correct.
Thus the solution simplifies to: For each x, compute r = x % 11. If (111 * r <= x) output YES else NO.
But wait: Let's test x=111. r = 111 % 11 = 1? Actually 111 mod 11 = 1 because 1110=110 remainder 1. Then 1111=111 <=111, condition says YES. And indeed 111 can be represented as one 111. That's fine. x=122: r=122%11=1 (since 1111=121 remainder 1), 1111=111 <=122 => YES: 122-111=11 => 111, works. x=133: r=133%11=1 (1112=132), 111<=133 => YES. x=144: r=1, 111<=144 => YES. x=155: r=155%11=1 (1114=154), 111<=155 => YES. x=166: r=1 (1115=165), YES. x=177: r=1? 1116=176 remainder 1, YES. x=188: r=1 (1117=187), YES. x=199: r=199%11=199-11*18=199-198=1, YES. So many numbers with residue 1 are YES even if they are less than 111? But for x=1 to 10 with r=1, 111> x, NO. x=12? 12%11=1, 111>12, NO. So works.
Now test x= 1000: 1000%11 = 1000-11*90=1000-990=10, so r=10, 1110 > 1000, condition says NO? But is 1000 representable? Let's check manually. Need 11a+111b=1000. Since 111 mod 11 =1, we need b ≡ 1000 mod 11 = 10 mod 11. So b = 10, 21, ... Smallest b=10 gives 1110 >1000, so not possible. b= -? No. So no representation. So 1000 is NO. But is it possible using larger repunits like 1111? 1111 >1000 can't. So 1000 is indeed NO. So condition says NO, correct.
But wait, what about x=2000? 2000%11 = 2000-11181=2000-1991=9, r=9, 1119=999 <=2000, condition says YES. Indeed we can take b=9, remainder=2000-999=1001, which is 1191? 1191=1001, yes, so a=91, sum=1001+999=2000. So YES.
Thus the simple condition works.
But is it always valid? Let's check a case: x=111*11 = 1221. r = 1221%11 = 0 => YES. Could also use 11 copies of 111, but condition gives YES.
Now, what about x=1099? r=10, 1110>1099 => NO. So it's consistent with Frobenius number.
Thus we have an O(1) solution: For each x, compute r = x % 11; if (r * 111 <= x) then YES else NO.
But is there any subtlety regarding the use of other repunits? Could there be a representation that uses, say, 1111 (which is 101*11) that would allow a number that does not satisfy the condition? For example, x=1000: Could we use 1111? No, too large. Could we use 111 and 1111? 1111 is >1000, so no. So fine.
But what about using 111 and 11 and also maybe 11111? But 11111 > 1000, so no. So no.
Thus the condition seems sound.
But wait: The set includes all repunits of length >=2, not just 11 and 111. Could there be a representation using multiple repunits, perhaps of different lengths, that yields a number that cannot be expressed as 11a+111b? We argued that all repunits are linear combinations of 11 and 111 with nonnegative integer coefficients. But we need to ensure that the representation using those repunits can be combined without issues: if we have a sum of several repunits, we can replace each repunit with its representation in terms of 11 and 111. The coefficients for 11 and 111 from each replacement are nonnegative integers. Summing them yields a representation as 11a+111b. So the set of sums is exactly the semigroup generated by 11 and 111. Therefore the condition holds.
But one more nuance: The representation of larger odd repunits as 100*R_{L-2}+11 uses coefficient 100 for the previous repunit. If we replace recursively, we eventually get representation with many 11's. So yes.
Thus the simple condition is correct.
But to be thorough, let's test a few more values manually with brute force for all x up to 2000, to see if condition matches. I'll simulate mentally a few borderline cases:
x=112: r=2? 111%? Actually 112%11 = 2? 11*10=110 remainder2 => 222>112 => NO? But check manually: can we make 112? Try b=1 => 112-111=1, not multiple of 11. b=0 => 112 not multiple of 11. So NO, matches.
x=113: r=3 => 333>113 => NO.
x=114: r=4 => 444>114 => NO.
x=115: r=5 => 555>115 => NO.
x=116: r=6 => 666>116 => NO.
x=117: r=7 => 777>117 => NO.
x=118: r=8 => 888>118 => NO.
x=119: r=9 => 999>119 => NO.
x=120: r=10 => 1110>120 => NO.
x=121: r=0 => YES.
x=122: r=1 => 111<=122 => YES.
x=123: r=2? 121 remainder2? 123%11 = 2? 1111=121 remainder2 => 222>123 => NO. But maybe we can use b=2? 1112=222>123, no. b=13? too high. So NO.
x=124: r=3 => 333>124 => NO.
x=125: r=4 => 444>125 => NO.
x=126: r=5 => 555>126 => NO.
x=127: r=6 => 666>127 => NO.
x=128: r=7 => 777>128 => NO.
x=129: r=8 => 888>129 => NO.
x=130: r=9 => 999>130 => NO.
x=131: r=10 => 1110>131 => NO.
x=132: r=0 => YES.
x=133: r=1 => 111<=133 => YES.
x=134: r=2 => 222>134 => NO.
... continues pattern.
So it seems pattern: The representable numbers are those where x is either multiple of 11, or at least 111 + multiple of 11, i.e., x >= 111 and x mod 11 = 1? Actually from the condition: if r != 0, we need x >= 111*r. So for r=1, need x >=111; for r=2, need x >=222; for r=3, need x >=333; ... for r=10, need x >=1110. So the non-multiples of 11 are representable only if they are at least 111 times the residue. So numbers like 122 (111+11) are okay. 133 (111+22) okay. 144 (111+33) okay. But 155 (111+44) okay, etc. So basically, if the remainder is r, you need to have at least one 111, plus enough 11's to fill the gap. But if r=1, you need at least one 111 to cover the remainder 1, then the rest must be multiple of 11. So x must be at least 111, and x-111 divisible by 11. That's x ≡ 1 mod 11 and x >=111. That matches condition: x%11=1 and x>=111. Similarly for r=2: need at least two 111's? Actually to get remainder 2, you need b ≡ 2 mod 11, smallest b=2, so need at least 222, then remainder divisible by 11. So condition: x%11=2 and x>=222. For r=3: x%11=3 and x>=333, etc. For r=10: x%11=10 and x>=1110.
So the simple condition is indeed equivalent.
Thus solution: For each test case, read x, compute r = x % 11, if (111 * r <= x) print "YES" else "NO".
But we need to be careful: 111 * r might overflow? r max is 10, 111*10=1110, which fits in int. x up to 1e9, fine.
So this is O(t) time.
But is there any scenario where this condition fails for numbers > 1099 but still not representable? According to Frobenius theorem, all numbers >= 1100 are representable. But our condition says for x=1100-1109, it gives YES, as shown. So it's fine.
However, we must double-check that the Frobenius number is indeed 1099. The Frobenius number for coprime a,b is ab - a - b. Here a=11, b=111. ab=1221, minus 11 minus 111 = 1099. So correct.
But wait: 11 and 111 are coprime? Yes, gcd(11,111)=1 as 111 mod 11 = 1, so gcd=1. So all numbers >1099 are representable. So our condition should give YES for all x >= 1100. Let's test x=1100: r=0 => YES. x=1101: r=1, 111<=1101 => YES. x=1102: r=2, 222<=1102 => YES. x=1103: r=3, 333<=1103 => YES. ... x=1109: r=9, 999<=1109 => YES. x=1110: r=10, 1110<=1110 => YES. x=1111: r=0 => YES. So all good.
Thus we can just implement the simple condition.
Now, before finalizing, we should also consider whether the problem might have included the number 1? The statement says "11, 111, 1111, 11111, …". So 1 is not included. So our reduction is correct.
But let's double-check the representation for numbers like 111111 (6 ones). This is even-length, so multiple of 11. Indeed 111111/11 = 10101, integer. So it's just 11 * 10101. So fine.
Now, edge case: x=0? Not in input.
Thus solution is straightforward.
But the problem is from Codeforces? I recall a problem "Can you make it?" or something similar. Actually it might be CF Round #710? There is a problem "1111" etc. I think it's CF problem 1526B? Actually there is a Codeforces problem "B. I Hate 1111" or something. Yes! It's Codeforces Round #1462? Actually there is problem "1526B - I Hate 1111". That problem asks: Given x, can it be represented as sum of 11 and 111? And the solution was: check if x%11 <= x/111? Or something like that. Indeed the known solution: For x >= 111*10? Actually known solution: for t queries, check if (x % 11) * 111 <= x, then YES else NO. Yes, that's exactly the problem. So this is a known Codeforces problem.
Thus our answer is correct.
Now we need to implement: read t, loop, read x, compute r = x % 11, if 111 * r <= x: print "YES", else "NO". Use Python or C++.
But note: There might be an alternative approach: For x>1099, always YES. But the condition works for all.
Thus we can produce the solution.
But let's double-check if there is any nuance: The problem statement says "some number of 11, 111, 1111, 11111, …". That includes numbers with any number of ones (>=2). So we considered all. So it's correct.
Now, I'll produce final answer.
But also think about potential pitfalls: The condition 111 * (x % 11) <= x fails for x = 1099 as we saw, but is 1099 truly not representable? Let's double-check with brute force: possible b values from 0 to 9:
b=0: 1099 %11 = 10? Actually 1099/11=99 remainder 10, not integer.
b=1: 1099-111=988, 988/11=89.818? 1189=979, remainder 9, so not integer.
b=2: 1099-222=877, 877/11=79.727, 1179=869, remainder 8.
b=3: 1099-333=766, 766/11=69.636, 1169=759 remainder7.
b=4: 1099-444=655, 655/11=59.545, 1159=649 remainder6.
b=5: 1099-555=544, 544/11=49.454, 1149=539 remainder5.
b=6: 1099-666=433, 433/11=39.363, 1139=429 remainder4.
b=7: 1099-777=322, 322/11=29.272, 1129=319 remainder3.
b=8: 1099-888=211, 211/11=19.181, 1119=209 remainder2.
b=9: 1099-999=100, 100/11=9.0909, not integer.
So no. So NO.
Thus answer correct.
Now, we can write the solution.
But wait, are there any numbers less than 111 that are representable besides multiples of 11? For x= something like 22,33,... Only multiples of 11. So condition works.
Now confirm that 111 * (x%11) may overflow in C++ if using 32-bit but r <=10, so product <=1110, fine.
Thus final solution is trivial.
But let's add an alternative: Many editorial solutions use the following: For i from 0 to 10, if 111i <= x and (x - 111i) % 11 == 0, then YES. That's also simple and safe. But our condition is even simpler.
So we can implement that.
I'll write the explanation in final answer: compute remainder r = x % 11. Then if 111 * r <= x, YES else NO.
However, before finalizing, let's test with some random numbers to ensure no off-by-one: x=0? Not needed.
So only 1099 is not representable. This matches Frobenius number being 1099.
Now, note that x=1100 is representable. So threshold 1100 works.
Thus answer is done.
Now, is there any need to consider that we might also be able to use 0? No.
Thus final solution: read t; for each x: if (x % 11) * 111 <= x: print("YES") else print("NO").
But we should also consider that x might be less than 111 and not a multiple of 11, then condition fails as expected.
Now implement.
Given t up to 10000, easy.
In Python, we can write:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
t = int(data[0])
out = []
for i in range(1, t+1):
x = int(data[i])
r = x % 11
if r * 111 <= x:
out.append("YES")
else:
out.append("NO")
sys.stdout.write("\n".join(out))
Edge: For x large, product fits.
Now, we must also ensure that we didn't misinterpret the set: "some number of 11, 111, 1111, 11111, …" Might also include numbers like 1? Usually "11, 111, 1111, ..." means numbers consisting of at least two 1's. So fine.
Thus final answer.
But wait: There's a known nuance: In the problem "I Hate 1111" the solution was: while x >= 0: if x % 11 == 0: YES; else x -= 111; and check if x >= 0. That yields same condition. But our condition is simpler.
Now I'll produce final explanation.
But before finalizing, let's verify with the sample: 33 => r=0 => YES; 144 => r=1 => 111<=144 => YES; 69 => r=3 => 333>69 => NO. matches.
Thus solution is correct.
Potential pitfalls: The problem might have t up to 10000, but x up to 10^9, product and modulo fine.
Now implement.
Now I'll write final answer in "final" channel. We need to check if a given integer (x) can be expressed as a sum of numbers of the form (11, 111, 1111, 11111, \dots) (any number of times).
Observe that every repunit of even length is a multiple of (11) (e.g., (1111 = 101 \cdot 11)), so it does not add new residues beyond those obtained by using only (11).
Moreover, every repunit of odd length (\ge 3) can be expressed as a combination of (11) and (111):
(111) itself is included,
(11111 = 100 \cdot 111 + 11),
and inductively (R_{k+2} = 100 \cdot R_k + 11).
Thus the set of all representable numbers is exactly the semigroup generated by (11) and (111):
[
x = 11a + 111b \quad (a,b \ge 0).
]
Since (\gcd(11,111)=1), the Frobenius number is (11\cdot111-11-111 = 1099). Hence every integer (x \ge 1100) can be represented. For smaller (x) we need a simple test.
Rewrite the condition:
(111 \equiv 1 \pmod{11}), so (x - 111b) must be divisible by (11).
Let (r = x \bmod 11). Then we need a non‑negative integer (b) such that (b \equiv r \pmod{11}) and (b \le \lfloor x/111 \rfloor).
The smallest candidate is (b = r). If (111 \cdot r \le x) (i.e., (r \le \lfloor x/111 \rfloor)), we can take (b = r) and (a = (x - 111r)/11). Otherwise, no such (b) exists.
This condition works for all (x) (including the trivial cases (x < 11) and (x \ge 1100)).
The algorithm runs in (O(1)) per test case, well within limits.
python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out = []
for i in range(1, t + 1):
x = int(data[i])
r = x % 11
if r * 111 <= x:
out.append("YES")
else:
out.append("NO")
sys.stdout.write("\n".join(out))
if __name__ == "__main__":
solve()