fork download
  1. import java.io.*;
  2. import java.util.Locale;
  3. import java.util.StringTokenizer;
  4.  
  5. public class TaskD {
  6. private final InputReader reader;
  7. private final OutputWriter writer;
  8.  
  9. public TaskD(InputReader reader, OutputWriter writer) {
  10. this.reader = reader;
  11. this.writer = writer;
  12. }
  13.  
  14. public static void main(String[] args) {
  15. InputReader reader = new InputReader(System.in);
  16. OutputWriter writer = new OutputWriter(System.out);
  17. new TaskD(reader, writer).run();
  18. writer.writer.flush();
  19. }
  20.  
  21. public void run() {
  22. int w = reader.nextInt(), m = reader.nextInt();
  23. if (w <= 3)
  24. writer.printf("YES\n");
  25. else {
  26. while (m != 0) {
  27. if (m % w != (w - 1) && m % w != 0 && m % w != 1) {
  28. writer.printf("NO\n");
  29. return;
  30. }
  31. m = (m + 1) / w;
  32. }
  33. writer.printf("YES\n");
  34. }
  35. }
  36.  
  37.  
  38. static class InputReader {
  39. public BufferedReader reader;
  40. public StringTokenizer tokenizer;
  41.  
  42. public InputReader(InputStream stream) {
  43. reader = new BufferedReader(new InputStreamReader(stream), 32768);
  44. tokenizer = null;
  45. }
  46.  
  47. public String next() {
  48. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  49. try {
  50. tokenizer = new StringTokenizer(reader.readLine());
  51. } catch (IOException e) {
  52. throw new RuntimeException(e);
  53. }
  54. }
  55. return tokenizer.nextToken();
  56. }
  57.  
  58. public int nextInt() {
  59. return Integer.parseInt(next());
  60. }
  61.  
  62. public double nextDouble() {
  63. return Double.parseDouble(next());
  64. }
  65.  
  66. public long nextLong() {
  67. return Long.parseLong(next());
  68. }
  69. }
  70.  
  71. static class OutputWriter {
  72. public PrintWriter writer;
  73.  
  74. OutputWriter(OutputStream stream) {
  75. writer = new PrintWriter(stream);
  76. }
  77.  
  78. public void printf(String format, Object... args) {
  79. writer.print(String.format(Locale.ENGLISH, format, args));
  80. }
  81. }
  82. }
  83.  
  84.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class TaskD is public, should be declared in a file named TaskD.java
public class TaskD {
       ^
1 error
stdout
Standard output is empty