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