fork(18) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <cstring>
  6. #include <deque>
  7. #include <time.h>
  8. #include <stack>
  9. #include <stdio.h>
  10. #include <map>
  11. #include <set>
  12. #include <string>
  13. #include <fstream>
  14. #include <queue>
  15. #define mp make_pair
  16. #define pb push_back
  17. #define PI 3.14159265358979323846
  18. #define MOD 1000000007
  19. #define INF ((ll)1e+15)
  20. #define x1 fldgjdflgjhrthrl
  21. #define x2 fldgjdflgrtyrtyjl
  22. #define y1 fldggfhfghjdflgjl
  23. #define y2 ffgfldgjdflgjl
  24. typedef long long ll;
  25. using namespace std;
  26. ll w,m,sz,i;
  27. ll a[40];
  28.  
  29. int main()
  30. {
  31. ll flag = 1;
  32. cin >> w >> m;
  33. while (m)
  34. {
  35. a[sz++] = m%w;
  36. m /= w;
  37. }
  38. for (i = 0; i <= sz; i++)
  39. if (a[i] != 0 && a[i] != 1 && a[i] != w-1 && a[i] != w)
  40. {
  41. flag = 0;
  42. break;
  43. }
  44. else
  45. {
  46. if (a[i] == w-1 || a[i] == w)
  47. a[i+1]++;
  48. }
  49. if (flag)
  50. cout << "YES" << endl;
  51. else
  52. cout << "NO" << endl;
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 3144KB
stdin
Standard input is empty
stdout
YES