#include <bits/stdc++.h>
using namespace std;
string s1, s2, s;
int ans, i, j, l1, l2, n, minx;
bool judge() {
  for (int k = 0; k < i; ++k)
    for (int l = 1; l < j; ++l)
      if (s[k + l * i] != s[k]) return false;
  return true;
}
int main() {
  cin >> s1 >> s2;
  s = s1 + s2;
  i = 1;
  l1 = s1.size();
  l2 = s2.size();
  minx = min(l1, l2);
  while (i <= minx) {
    if (l1 % i == 0 && l2 % i == 0) {
      j = (l1 + l2) / i;
      if (judge()) ++ans;
    }
    i++;
  }
  printf("%d\n", ans);
  return 0;
}
