#include <bits/stdc++.h>
using namespace std;
char s[2][100010];
int fail[2][100010], len[2];
int min(int a, int b) { return a < b ? a : b; }
void kmp(int tp) {
  int i, k;
  len[tp] = strlen(s[tp] + 1);
  memset(fail[tp], 0, sizeof(fail[tp]));
  for (i = 2; i <= len[tp]; i++) {
    k = fail[tp][i - 1];
    while (k && s[tp][k + 1] != s[tp][i]) k = fail[tp][k];
    if (s[tp][k + 1] == s[tp][i]) fail[tp][i] = k + 1;
  }
  return;
}
int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int judge(int tp) {
  int i, t, x, ans = len[tp];
  for (i = len[tp]; i; i = fail[tp][i])
    if (len[tp] % i == 0) {
      t = len[tp], x = len[tp] - i;
      while (x) {
        if (fail[tp][t] > x) t = fail[tp][t];
        if (fail[tp][t] != x) goto A;
        t -= i;
        x -= i;
      }
      ans = min(ans, i);
    A:;
    }
  return ans;
}
int getans() {
  int i, p, t;
  kmp(0), kmp(1);
  p = min(len[0], len[1]);
  for (i = 1; i <= p; i++)
    if (s[0][i] != s[1][i]) return 0;
  i = judge(0), p = judge(1);
  if (i != p) return 0;
  int h = gcd(len[0], len[1]);
  p = 0;
  for (t = i; t <= h; t += i)
    if (h % t == 0) p++;
  return p;
}
int main() {
  while (~scanf("%s%s", s[0] + 1, s[1] + 1)) printf("%d\n", getans());
  return 0;
}
