#include <bits/stdc++.h>
using namespace std;
bool check(string s, string t) {
  int n = s.length(), n1 = t.length();
  for (int i = 0; i < n; i += n1)
    if (s.substr(i, n1) != t) return false;
  return true;
}
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int n1 = s1.length(), n2 = s2.length(), ans = 0;
  for (int i = 1; i <= max(n1, n2); i++)
    if (n1 % i == 0 && n2 % i == 0 && check(s1, s1.substr(0, i)) &&
        check(s2, s1.substr(0, i)))
      ans++;
  printf("%d", ans);
  return 0;
}
