#include<bits/stdc++.h>
using namespace std;
map<int , bool > mp;
void solve() {
int n;
cin >> n;
if(n == -1) continue;
if(mp[n]) cout << "YES\n";
else cout << "NO\n";
solve();
}
signed main(){
int n = 1e6 + 5;
int fact[20];
fact[0] = 1;
for (int i = 1; i<=11; i++){
fact[i] = fact[i-1] * i;
}
mp[0] = true;
mp[1] = true;
for(int i = 1; i<=11; i++){
vector<int> temp;
for(auto it : mp) {
// cout << it.first << " " << fact[i] << endl;
if(it.first + fact[i] > n) continue;
temp.push_back(it.first + fact[i]);
}
for(auto it : temp) mp[it] = true;
}
solve();
}