#include <bits/stdc++.h>
using namespace std;
using namespace std;
char s1[100100], s2[100100];
bool check(int len, char s[]) {
  int n = strlen(s);
  if (len > n) return false;
  if (n % len) return false;
  int t = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != s1[t]) {
      return false;
    }
    t = (t + 1) % len;
  }
  return true;
}
void solve() {
  scanf("%s%s", s1, s2);
  int n, m;
  n = strlen(s1);
  m = strlen(s2);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      if (check(i, s1) && check(i, s2)) {
        ans++;
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
