#include <bits/stdc++.h>
using namespace std;
string str, str2;
string dv, dv2;
bool check(string txt, string pat) {
  int ix = 0;
  for (int i = 0; i <= txt.length() - 1; i += 1) {
    if (txt[i] != pat[ix]) return false;
    ix = (ix + 1) % pat.size();
  }
  return ix == 0;
}
string getDiv(string s) {
  string pat = "";
  string ret;
  for (int i = 0; i <= s.length() - 1; i += 1) {
    pat += s[i];
    if (s.length() % (i + 1) != 0) continue;
    if (check(s, pat)) {
      return pat;
      break;
    }
  }
  return ret;
}
bool check2(string pat1, string pat2) {
  if (pat1.length() != pat2.length()) {
    return false;
  }
  for (int i = 0; i <= pat1.length() - 1; i += 1) {
    if (pat1[i] != pat2[i]) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> str >> str2;
  int len1 = str.length(), len2 = str2.length();
  dv = getDiv(str);
  int ans = 0, len = 1;
  if (dv.length() > 0 && check(str2, dv)) {
    while (len * dv.length() <= len1 && len * dv.length() <= len2) {
      if (len1 % (len * dv.length()) == 0 && len2 % (len * dv.length()) == 0) {
        ans++;
      }
      len++;
    }
  }
  cout << ans << endl;
  return 0;
}
