PROBLEM 36: Dislike of Threes
Problem Reference: Codeforces
Polycarp doesn't like integers that are divisible by or end with the digit in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too.
Polycarp starts to write out the positive (greater than Output the -th element of this sequence (the elements are numbered from ).
The first line contains one integer () — the number of test cases. Then test cases follow.
Each test case consists of one line containing one integer ().
For each test case, output in a separate line one integer — the -th element of the sequence that was written out by Polycarp.
Solution:
- t = int(input())
- while 0 < t:
- n = int(input())
- i = 1
- j = 1
- while j == 1:
- if i % 3 == 0 or i % 10 == 3:
- i = i + 1
- else:
- n = n - 1
- if n == 0:
- print(i)
- break
- i = i + 1
- t = t - 1
10 1 2 3 4 5 6 7 8 9 1000
1 2 4 5 7 8 10 11 14 1666
No comments:
Post a Comment