Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. private void solution() throws IOException {
  2. int n = in.nextInt() - 1;
  3. int bad = in.nextInt();
  4. int length = 1;
  5. while (count(length, bad) <= n) {
  6. n -= count(length, bad);
  7. ++length;
  8. }
  9. String res = "";
  10. for (int i = 0; i < length; ++i) {
  11. for (int j = 0; j < 10; ++j) {
  12. if (j == 0 && i == 0) {
  13. continue;
  14. } else if (j == bad) {
  15. continue;
  16. } else {
  17. int more = (int) Math.pow(9, length - i - 1);
  18. if (more > n) {
  19. res += j;
  20. break;
  21. } else {
  22. n -= more;
  23. }
  24. }
  25. }
  26. }
  27. out.println(res);
  28. }
  29.  
  30. private int count(int length, int bad) {
  31. if (bad == 0) {
  32. return (int) Math.pow(9, length);
  33. } else {
  34. return (int) (8 * Math.pow(9, length - 1));
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement