-
Notifications
You must be signed in to change notification settings - Fork 21
/
magical coins
61 lines (50 loc) · 1.24 KB
/
magical coins
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
In a magical land, the currency is based on certain 𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑠
. These 𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑠
(coins) are of the order 11,111,1111,11111,...
and so on.
Gopal has bought an item, determine if it is possible for him to pay with the help of these coins.
He can use any coin 𝑎𝑛𝑦
number of times.
Input
The input consists of multiple test cases.
The first line contains a single integer 𝑡
(1≤𝑡≤104
) — The number of test cases.
Each test case 𝑡
contains a single integer 𝑛
(1≤𝑛≤109
) — Cost of the item.
Output
For each test case, output YES if it is possible to pay, otherwise output NO.
Example
InputCopy
3
33
144
69
OutputCopy
YES
YES
NO
Note
For 𝑛=33
, Gopal can use three coins of 11
,so the output is YES.
For 𝑛=144
, Gopal can use one 𝐜𝐨𝐢𝐧
of 111
and three coins of 11
to make 144, so the output is YES.
For 𝑛=69
, no combination is possible, so the output is NO.
#code:
t = int(input())
for j in range(t):
n = int(input())
for i in range(n // 111 + 1):
remain = n - i * 111
if remain >= 0 and remain % 11 == 0:
print("YES")
break
else:
print("NO")