#include <bits/stdc++.h>
using namespace std;
char str1[100001];
char str2[100001];
int ff(char *str, int k, int n) {
  int m = n / k;
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < k; ++j) {
      if (str[j] != str[(j + i * k) % n]) return 0;
    }
  }
  return 1;
}
int pp(int n, char *str1, char *str2) {
  for (int i = 0; i < n; ++i)
    if (str1[i] != str2[i]) return 0;
  return 1;
}
int main() {
  while (scanf("%s%s", str1, str2) != EOF) {
    int len1, len2, i;
    len1 = strlen(str1);
    len2 = strlen(str2);
    int len = (len1 > len2 ? len2 : len1);
    int ans = 0;
    for (i = 1; i <= len; ++i) {
      if (len1 % i == 0 && len2 % i == 0) {
        if (ff(str1, i, len1) && ff(str2, i, len2) && pp(i, str1, str2)) {
          ans++;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
