#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; bool isDiv(string s, int d){ int cur = 0; rep(i,s.size()){ cur = cur * 10 + (int)(s[i]-'0'); while( cur >= d ) cur -= d; } return cur == 0; } int main(){ string s; cin >> s; int l = s.size(); vector occ_d; rep(i,l) occ_d.emplace_back( s[i]-'0' ); sort(occ_d.begin(), occ_d.end()); occ_d.erase( unique(occ_d.begin(), occ_d.end()), occ_d.end() ); if(occ_d.size() == 1){ cout << s << endl; return 0; } int gcd = 0; for(int a : occ_d){ for(int b : occ_d){ int dif = abs(9*a - 9*b); gcd = __gcd(gcd, dif); } } int ans = 1; for(int i=gcd;i>=1;i--){ if(gcd%i == 0 and isDiv(s, i)){ ans = i; break; } } cout << ans << endl; }