#include <bits/stdc++.h>
using namespace std;
const int prime = 151;
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int slen, tlen;
string t, s;
unsigned long long hs1[maxn], base[maxn], hs2[maxn];
inline unsigned long long check(int l, int r, unsigned long long hs[]) {
  return hs[r] - hs[l - 1] * base[r - l + 1];
}
inline int solve() {
  slen = s.length(), tlen = t.length();
  base[0] = 1;
  for (int i = 1; i <= max(slen, tlen); ++i) base[i] = base[i - 1] * prime;
  for (int i = 1; i <= tlen; ++i) hs2[i] = hs2[i - 1] * prime + t[i - 1];
  for (int i = 1; i <= slen; ++i) hs1[i] = hs1[i - 1] * prime + s[i - 1];
  int ans = 0;
  if (s.find(t) == string::npos && t.find(s) == string::npos) return 0;
  if (tlen < slen) {
    for (int i = 1; i <= tlen; ++i) {
      if (check(1 + i, tlen, hs2) == check(1, tlen - i, hs2) && tlen % i == 0 &&
          check(1 + i, slen, hs1) == check(1, slen - i, hs1) && slen % i == 0)
        ++ans;
    }
  } else {
    for (int i = 1; i <= slen; ++i) {
      if (check(1 + i, slen, hs1) == check(1, slen - i, hs1) && slen % i == 0 &&
          check(1 + i, tlen, hs2) == check(1, tlen - i, hs2) && tlen % i == 0)
        ++ans;
    }
  }
  return ans;
}
int main() {
  {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  cin >> t >> s;
  cout << solve();
  return 0;
}
