#include <bits/stdc++.h>
using namespace std;
const int MX = 100005;
long long md = 1e9 + 7;
long long N, M;
string s1, s2;
vector<int> f1, f2;
vector<int> pre(string pat) {
  int m = pat.size();
  vector<int> v(m);
  for (int i = 1, k = 0; i < m; i++) {
    while (k > 0 && pat[k] != pat[i]) k = v[k - 1];
    if (pat[k] == pat[i])
      v[i] = ++k;
    else
      v[i] = k;
  }
  return v;
}
int kmp(string str, string pat) {
  int n = str.size(), ret = 0;
  int m = pat.size();
  vector<int> v = pre(pat);
  for (int i = 0, k = 0; i < n; i++) {
    while (k > 0 && pat[k] != str[i]) k = v[k - 1];
    if (pat[k] == str[i]) ++k;
    if (k == m) {
      ret++;
      k = v[k - 1];
    }
  }
  return ret;
}
int match(string pp, string org) {
  int i = 0, j = 0;
  while (i < org.size()) {
    if (i % pp.size() == 0) j = 0;
    if (pp[j] != org[i]) return 0;
    i++;
    j++;
  }
  return 1;
}
string sub(int e, string org) {
  string sss = "";
  sss.clear();
  for (int i = 0; i < e; i++) sss += org[i];
  return sss;
}
map<string, int> ans;
int main() {
  cin >> s1 >> s2;
  f1 = pre(s1);
  f2 = pre(s2);
  int last = f1[f1.size() - 1];
  int b = 0, res = 0;
  while (last != 0) {
    b++;
    if (s1.size() % last || s2.size() % last) {
      last = f1[last - 1];
      continue;
    }
    string su = sub(last, s1);
    if (ans.find(su) != ans.end()) {
      last = f1[last - 1];
      continue;
    }
    if (match(su, s1) && match(su, s2)) res++, ans[su]++;
    last = f1[last - 1];
  }
  last = f2[f2.size() - 1];
  while (last != 0) {
    if (s1.size() % last || s2.size() % last) {
      last = f2[last - 1];
      continue;
    }
    string su = sub(last, s2);
    if (ans.find(su) != ans.end()) {
      last = f2[last - 1];
      continue;
    }
    if (match(su, s1) && match(su, s2)) res++, ans[su]++;
    last = f2[last - 1];
  }
  char c = s1[0];
  bool flag = 1;
  if (s1.size() == s2.size())
    for (int i = 0; i < s1.size(); i++) {
      if (s1[i] != s2[i]) flag = 0;
    }
  else
    flag = 0;
  if (flag) res++;
  cout << res << endl;
  return 0;
}
