#include <bits/stdc++.h>
using namespace std;
int cnt[200100 + 1];
const int mod = 1e9 + 7;
void solve() {
  string s1, s2;
  cin >> s1 >> s2;
  if (s2.size() > s1.size()) swap(s1, s2);
  vector<int> v;
  int n = s2.size();
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (n / i != i) v.push_back(n / i);
    }
  }
  sort(v.begin(), v.end());
  vector<string> str;
  for (auto l : v) {
    string tmp;
    set<string> st;
    for (int j = 0; j < n;) {
      tmp = s2.substr(j, l);
      j += l;
      st.insert(tmp);
    }
    if ((int)st.size() == 1) {
      str.push_back(tmp);
    }
  }
  int ans = 0;
  for (int i = 0; i < str.size(); i++) {
    string tmp = str[i];
    if ((int)s1.size() % (int)tmp.size() != 0) continue;
    int l = tmp.size();
    string cur;
    set<string> st;
    for (int j = 0; j < s1.size();) {
      cur = s1.substr(j, l);
      j += l;
      st.insert(cur);
    }
    if (st.size() == 1) {
      auto it = st.begin();
      if (*it == tmp) ans++;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
