#include <bits/stdc++.h>
using namespace std;
int F[100100];
int n, m;
int f(string P) {
  int i = 0, j = -1, m = P.size();
  F[0] = -1;
  while (i < m) {
    while (j >= 0 && P[i] != P[j]) j = F[j];
    i++;
    j++;
    F[i] = j;
  }
  return F[m];
}
int main() {
  string s, t;
  while (cin >> s >> t) {
    n = s.size();
    m = t.size();
    int p = n - f(s);
    int q = m - f(t);
    if (n % p != 0) p = n;
    if (m % q != 0) q = m;
    if (p == q) {
      bool sw = 1;
      for (int i = 0; i < p; i++)
        if (s[i] != t[i]) sw = 0;
      if (sw) {
        p = n / p;
        q = m / q;
        int c = 0;
        for (int i = 1; i <= min(p, q); i++) {
          if (p % i == 0 and q % i == 0) c++;
        }
        cout << c << endl;
      } else
        cout << "0\n";
    } else
      cout << "0\n";
  }
  return 0;
}
