-
Notifications
You must be signed in to change notification settings - Fork 1
/
552C - Vanya and Scales.cpp
45 lines (45 loc) · 1.08 KB
/
552C - Vanya and Scales.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<vector>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
int ak[100000];
int main(void)
{
LL n,m;
while(scanf("%lld %lld",&n,&m)!=EOF)
{
int flag = 0;
int cn = 0;
while(m)
{
ak[cn++] = m%n;
m/=n;
}
int d = 0;
if(n==2)printf("YES\n");
else
{for(int i = 0; i < cn; i++)
{
ak[i]+=d;
if(ak[i]==n-1)
{
ak[i]++;
}
d = ak[i]/n;
ak[i]=ak[i]%n;
if(ak[i]!=0&&ak[i]!=1)
flag = 1;
}
if(flag)printf("NO\n");
else printf("YES\n");}
}
return 0;
}