Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int next(int a) {
- bool forbidden[10] = {};
- {
- int t = a;
- do {
- forbidden[t % 10] = true;
- t /= 10;
- } while (t != 0);
- }
- for (int i = a + 1; ; i++) {
- int t = i;
- bool good = true;
- do {
- if (forbidden[t % 10]) {
- good = false;
- }
- t /= 10;
- } while (t != 0);
- if (good)
- return i;
- }
- }
- void research() {
- int a = 0;
- for (int i = 1; i <= 500; i++) {
- cout << i << " -> " << a << endl;
- a = next(a);
- }
- }
- int main() {
- /*research();*/
- int n;
- cin >> n;
- if (n < 21) {
- int a = 0;
- for (int i = 1; i < n; i++) {
- a = next(a);
- }
- cout << a;
- } else {
- int firstDigit = (n - 21) % 8 + 2;
- int secondDigit = (n - 21) % 2;
- int secondDigitCount = (n - 21) / 8 + 2;
- cout << firstDigit;
- for (int i = 0; i < secondDigitCount; i++) {
- cout << secondDigit;
- }
- }
- return 0;
- }
- /*
- research():
- 1 -> 0
- 2 -> 1
- 3 -> 2
- 4 -> 3
- 5 -> 4
- 6 -> 5
- 7 -> 6
- 8 -> 7
- 9 -> 8
- 10 -> 9
- 11 -> 10
- 12 -> 22
- 13 -> 30
- 14 -> 41
- 15 -> 50
- 16 -> 61
- 17 -> 70
- 18 -> 81
- 19 -> 90
- 20 -> 111
- 21 -> 200
- 22 -> 311
- 23 -> 400
- 24 -> 511
- 25 -> 600
- 26 -> 711
- 27 -> 800
- 28 -> 911
- 29 -> 2000
- 30 -> 3111
- 31 -> 4000
- 32 -> 5111
- 33 -> 6000
- 34 -> 7111
- 35 -> 8000
- 36 -> 9111
- 37 -> 20000
- 38 -> 31111
- 39 -> 40000
- 40 -> 51111
- 41 -> 60000
- 42 -> 71111
- 43 -> 80000
- 44 -> 91111
- 45 -> 200000
- 46 -> 311111
- 47 -> 400000
- 48 -> 511111
- 49 -> 600000
- 50 -> 711111
- 51 -> 800000
- 52 -> 911111
- 53 -> 2000000
- 54 -> 3111111
- 55 -> 4000000
- 56 -> 5111111
- 57 -> 6000000
- 58 -> 7111111
- 59 -> 8000000
- 60 -> 9111111
- 61 -> 20000000
- 62 -> 31111111
- 63 -> 40000000
- 64 -> 51111111
- 65 -> 60000000
- 66 -> 71111111
- 67 -> 80000000
- 68 -> 91111111
- TIME LIMIT
- */
Add Comment
Please, Sign In to add comment