#include <bits/stdc++.h>
using namespace std;
char a[100001], b[100001];
int ans;
int la, lb;
int i, j;
int g;
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = a;
    a = b;
    b = t % b;
  }
  return a;
}
int tr(int l) {
  int i, p, q, r, mx;
  p = q = r = 0;
  mx = max(la, lb);
  for (i = 0; i < mx; i++) {
    if (p < la && a[p] != a[r]) {
      return 0;
    }
    if (q < lb && b[q] != a[r]) {
      return 0;
    }
    p++;
    q++;
    r = (r + 1) % l;
  }
  return 1;
}
int main() {
  while (scanf("\n%s\n%s", a, b) != EOF) {
    la = strlen(a);
    lb = strlen(b);
    g = gcd(la, lb);
    ans = 0;
    for (i = 1; i * i <= g; i++)
      if (g % i == 0) {
        ans += tr(i);
        if (g != i * i) ans += tr(g / i);
      }
    printf("%d\n", ans);
  }
}
