#include <bits/stdc++.h>
using namespace std;
class B_808 {
 public:
  int main() {
    int n, k, a[200005];
    double ans = 0.0, sum = 0.0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < k; i++) sum += a[i];
    ans += sum / ((double)n - k + 1);
    for (int i = k; i < n; i++) {
      sum += a[i] - a[i - k];
      ans += sum / ((double)n - k + 1);
    }
    cout << std::fixed;
    cout << std::setprecision(6) << ans << endl;
    return 0;
  }
};
class C_43 {
 public:
  int main() {
    int n, a, ans = 0, m[3] = {0};
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a;
      m[a % 3]++;
    }
    ans += m[0] / 2;
    ans += min(m[1], m[2]);
    cout << ans << endl;
    return 0;
  }
};
class B_814 {
 private:
  int n, a[1004], b[1004];
  bool isValid() {
    int d = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) d++;
    }
    return d == 1;
  }

 public:
  int main() {
    int missing, rep = 0;
    set<int> s;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) s.insert(i);
    for (int i = 0; i < n; i++) {
      if (s.find(a[i]) != s.end()) {
        s.erase(a[i]);
      } else {
        rep = a[i];
      }
    }
    missing = *s.begin();
    for (int i = 0; i < n; i++) {
      if (a[i] == rep) {
        a[i] = missing;
        if (isValid()) {
          break;
        } else {
          a[i] = rep;
        }
      }
    }
    for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? "\n" : " ");
    return 0;
  }
};
class C_628 {
 public:
  int main() {
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    string output = s;
    for (int i = 0; i < n && k > 0; i++) {
      if (abs('a' - s[i]) >= abs('z' - s[i])) {
        if (abs('a' - s[i]) < k) {
          output[i] = 'a';
          k -= abs('a' - s[i]);
        } else {
          output[i] = s[i] - k;
          k = 0;
        }
      } else {
        if (abs('z' - s[i]) < k) {
          output[i] = 'z';
          k -= abs('z' - s[i]);
        } else {
          output[i] = s[i] + k;
          k = 0;
        }
      }
    }
    if (k == 0) {
      cout << output;
    } else {
      cout << "-1";
    }
    return 0;
  }
};
class D_182 {
 private:
  bool verify(string &d, string &s) {
    int n = (int)d.length();
    for (int i = 0; i < s.length(); i++) {
      if (d[i % n] != s[i]) {
        return false;
      }
    }
    return true;
  }

 public:
  int main() {
    string s1, s2, d;
    cin >> s1 >> s2;
    set<string> divisors;
    int ans = 0;
    int n = (int)s1.size();
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        d = s1.substr(0, i);
        if (verify(d, s1)) {
          divisors.insert(d);
        }
        d = s1.substr(0, n / i);
        if (verify(d, s1)) {
          divisors.insert(d);
        }
      }
    }
    n = (int)s2.size();
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        d = s2.substr(0, i);
        if (verify(d, s2) && divisors.find(d) != divisors.end()) {
          ans++;
        }
        if (i * i == n) continue;
        d = s2.substr(0, n / i);
        if (verify(d, s2) && divisors.find(d) != divisors.end()) {
          ans++;
        }
      }
    }
    cout << ans;
    return 0;
  }
};
int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  D_182().main();
  return 0;
}
