#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1000000007) {
  return ((a % p) * (b % p)) % p;
}
long long multbig(long long a, long long b, long long mod) {
  if (a == 0 or b == 0) return 0;
  if (a == 1 or b == 1) return (a * b) % mod;
  long long cur = multbig(a, b / 2, mod);
  cur = (2 * cur) % mod;
  if (b % 2) cur = (cur + a) % mod;
  return cur;
}
long long add(long long a, long long b, long long p = 1000000007) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1LL) {
    if (k & 1LL) r = mult(r, n, p);
    n = mult(n, n, p);
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
long long inv_euclid(long long a, long long m = 1000000007) {
  long long m0 = m;
  long long second = 0, first = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = second;
    second = first - q * second;
    first = t;
  }
  if (first < 0) first += m0;
  return first;
}
vector<int> v;
void solve() {
  string s, t;
  cin >> s >> t;
  int n = min((int)s.size(), (int)t.size());
  for (int i = 1; i < n + 1; i++) {
    if ((int)s.size() % i || (int)t.size() % i) continue;
    v.push_back(i);
  }
  sort((v).begin(), (v).end());
  int ans = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    if (s.substr(0, v[i]) == t.substr(0, v[i])) {
      int re = (int)s.size() / v[i];
      int ee = (int)t.size() / v[i];
      string ss, tt;
      while (re--) ss += s.substr(0, v[i]);
      while (ee--) tt += t.substr(0, v[i]);
      if (ss == s && tt == t) ans++;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
