Friday, 10 December 2021

Dislike of Threes Problem !!!

 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 ).


Input:

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  ().


Output:

For each test case, output in a separate line one integer  — the -th element of the sequence that was written out by Polycarp.


Solution:


  1. t = int(input())
  2. while 0 < t:
  3. n = int(input())
  4. i = 1
  5. j = 1
  6. while j == 1:
  7. if i % 3 == 0 or i % 10 == 3:
  8. i = i + 1
  9. else:
  10. n = n - 1
  11. if n == 0:
  12. print(i)
  13. break
  14. i = i + 1
  15. t = t - 1


The above solution is in python language.



Example
input
10
1
2
3
4
5
6
7
8
9
1000
output
1
2
4
5
7
8
10
11
14
1666

No comments:

Post a Comment

Rearrange an array with O(1) extra space

  PROBLEM 61:  Rearrange an array with O(1) extra space (For best view experience, view in windows version) Problem Reference : GeeksForGeek...