#include <bits/stdc++.h>
int strlen(char *str) {
  int len = 0;
  for (int i = 0; str[i] != '\0'; i++) {
    len++;
  }
  return len;
}
int countDivisor(char *a, char *b, int m) {
  int blen = strlen(b);
  for (int i = 0; i < blen; i++) {
    if (b[i] != a[i % m]) return 0;
  }
  return 1;
}
int main() {
  char a[100005], b[100005];
  while (scanf("%s%s", a, b) == 2) {
    int alen = strlen(a);
    int blen = strlen(b);
    int sz = (alen > blen) ? alen : blen;
    int ans = 0;
    for (int i = 1; i <= sz; i++) {
      if (alen % i == 0 && blen % i == 0) {
        ans += countDivisor(a, a, i) & countDivisor(a, b, i);
      }
    }
    printf("%d\n", ans);
  }
}
