#include <bits/stdc++.h>
using namespace std;
int l1, l2, d, n, m, i, j, k, ma;
string s1, s2;
char c[100005];
map<long long, bool> M;
long long X;
bool f(int L) {
  for (j = 0; j < L; j++)
    if (s1[j] != s2[j]) return 0;
  for (k = 1; (k * L + L) <= l1; k++)
    for (j = 0; j < L; j++)
      if (s1[k * L + j] != s1[(k - 1) * L + j]) return 0;
  for (k = 1; (k * L + L) <= l2; k++)
    for (j = 0; j < L; j++)
      if (s2[k * L + j] != s2[(k - 1) * L + j]) return 0;
  return 1;
}
int main() {
  scanf("%s", &c);
  s1 = c;
  scanf("%s", &c);
  s2 = c;
  l1 = s1.size();
  l2 = s2.size();
  n = min(l1, l2);
  for (i = 1; i <= n; i++)
    if (l1 % i == 0 & l2 % i == 0)
      if (f(i)) m++;
  cout << m << endl;
}
