#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2, t;
  int j, n, m;
  cin >> s1 >> s2;
  if (s1.length() > s2.length()) {
    t = s1;
    s1 = s2;
    s2 = t;
  }
  int cnt = 0;
  n = s1.length();
  m = s2.length();
  for (int i = 1; i <= n; i++) {
    if (n % i != 0 || m % i != 0) continue;
    for (j = 0; j < n; j++) {
      if (s1[j] != s1[j % i] || s2[j] != s2[j % i] || s1[j] != s2[j]) break;
    }
    if (j != n) continue;
    for (j = n; j < m; j++) {
      if (s2[j] != s2[j % i]) break;
    }
    if (j != m) continue;
    cnt++;
  }
  cout << cnt;
  return 0;
}
