#include <bits/stdc++.h>
using namespace std;
long long solve(string s, long long l) {
  long long len = 0, lps[l], i = 1;
  lps[0] = 0;
  while (i < l) {
    if (s[i] == s[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len == 0) {
        lps[i] = 0;
        i++;
      } else
        len = lps[len - 1];
    }
  }
  return lps[l - 1];
}
int main() {
  string x, y, s1, s2, a, b;
  long long i, val1, val2, l1, l2, c = 0, temp1, temp2;
  map<string, long long> m;
  m.clear();
  cin >> a;
  cin >> b;
  l1 = a.length();
  l2 = b.length();
  val1 = solve(a, l1);
  m[a] = 1;
  if (val1 > 0 && l1 % (l1 - val1) == 0) {
    x = "";
    for (i = 0; i < l1 - val1; i++) x += a[i];
    s1 = "";
    temp1 = l1 / (l1 - val1);
    for (i = 1; i < temp1; i++) {
      s1 += x;
      if (temp1 % i == 0) {
        m[s1] = 1;
      }
    }
  }
  val2 = solve(b, l2);
  if (m[b] == 1) c++;
  if (val2 > 0 && l2 % (l2 - val2) == 0) {
    y = "";
    for (i = 0; i < l2 - val2; i++) y += b[i];
    s2 = "";
    temp2 = l2 / (l2 - val2);
    for (i = 1; i < temp2; i++) {
      s2 += y;
      if (temp2 % i == 0) {
        if (m[s2] == 1) c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}
