#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int l1, l2;
int check(int i) {
  for (int j = i + 1; j < l1; j++)
    if (s1[j] != s1[j % (i + 1)]) return 0;
  for (int j = 0; j < l2; j++)
    if (s2[j] != s1[j % (i + 1)]) return 0;
  return 1;
}
int main() {
  cin >> s1 >> s2;
  int tot = 0;
  l1 = s1.size(), l2 = s2.size();
  for (int i = 1; i <= min(l1, l2) && s1[i - 1] == s2[i - 1]; i++)
    if (l1 % i == 0 && l2 % i == 0) tot += check(i - 1);
  cout << tot << endl;
  return 0;
}
