#include #include using namespace std; bool appear[15]; bool factor(string s, int mod) { int x = 0; for(char c : s) { x = x * 10 + (c - '0'); x %= mod; } return !x; } int main() { string n; cin >> n; for(auto c : n) { appear[c - '0'] = true; } int g = 0; for(int i = 0; i <= 9; i++) { for(int j = 0; j < i; j++) { if(appear[i] and appear[j]) { g = gcd(g, 9 * (i - j)); } } } if(!g) { cout << n << endl; return 0; } for(int i = g; i >= 1; i--) { if(g % i == 0 and factor(n, i)) { cout << i; return 0; } } }