fork(1) download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Main {
  6.  
  7. public static void main(String[] args) throws IOException{
  8. Scanner sc = new Scanner(System.in);//new File("input.txt"));
  9. PrintWriter pw = new PrintWriter(System.out);//new File("output.txt"));
  10. int w = sc.nextInt(), m = sc.nextInt();
  11. int flag = 1;
  12. int a[] = new int[40];
  13. for (int i = 0; i < 35; i++)
  14. a[i] = 0;
  15. int sz = 0;
  16. while (m > 0)
  17. {
  18. a[sz++] = m%w;
  19. m /= w;
  20. }
  21. for (int i = 0; i <= sz; i++)
  22. if (a[i] != 0 && a[i] != 1 && a[i] != w-1 && a[i] != w)
  23. {
  24. flag = 0;
  25. break;
  26. }
  27. else
  28. {
  29. if (a[i] == w-1 || a[i] == w)
  30. a[i+1]++;
  31. }
  32. if (flag == 1)
  33. pw.println("YES");
  34. else
  35. pw.println("NO");
  36. pw.close();
  37. }
  38. }
  39.  
Runtime error #stdin #stdout #stderr 0.1s 380608KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:907)
	at java.util.Scanner.next(Scanner.java:1530)
	at java.util.Scanner.nextInt(Scanner.java:2160)
	at java.util.Scanner.nextInt(Scanner.java:2119)
	at Main.main(Main.java:10)