Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void solution() throws IOException {
- int n = in.nextInt() - 1;
- int bad = in.nextInt();
- int length = 1;
- while (count(length, bad) <= n) {
- n -= count(length, bad);
- ++length;
- }
- String res = "";
- for (int i = 0; i < length; ++i) {
- for (int j = 0; j < 10; ++j) {
- if (j == 0 && i == 0) {
- continue;
- } else if (j == bad) {
- continue;
- } else {
- int more = (int) Math.pow(9, length - i - 1);
- if (more > n) {
- res += j;
- break;
- } else {
- n -= more;
- }
- }
- }
- }
- out.println(res);
- }
- private int count(int length, int bad) {
- if (bad == 0) {
- return (int) Math.pow(9, length);
- } else {
- return (int) (8 * Math.pow(9, length - 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement