#include <bits/stdc++.h>
using namespace std;
string s[2];
int a[2][200050];
int sq[2];
int main() {
  cin >> s[0];
  cin >> s[1];
  for (int k = 0; k < 2; k++) {
    if (((int)(s[k]).size()) == 1)
      sq[k] = 1;
    else {
      int p = 0;
      for (int i = 1; i < ((int)(s[k]).size()); i++) {
        while (p > 0 && s[k][i] != s[k][p]) {
          p = a[k][p - 1];
        }
        if (s[k][i] == s[k][p]) p++;
        a[k][i] = p;
      }
      if (((int)(s[k]).size()) %
              (((int)(s[k]).size()) - a[k][((int)(s[k]).size()) - 1]) ==
          0) {
        sq[k] = ((int)(s[k]).size()) - a[k][((int)(s[k]).size()) - 1];
      } else
        sq[k] = ((int)(s[k]).size());
    }
  }
  int ok = 1;
  if (sq[0] == sq[1]) {
    for (int i = 0; i < sq[0]; i++)
      if (s[0][i] != s[1][i]) ok = 0;
    if (ok) {
      int st = sq[0];
      int res = 0;
      int mnoz = 1;
      while (mnoz * st <= ((((int)(s[0]).size())) < (((int)(s[1]).size()))
                               ? (((int)(s[0]).size()))
                               : (((int)(s[1]).size())))) {
        if (((int)(s[0]).size()) % (mnoz * st) == 0 &&
            ((int)(s[1]).size()) % (mnoz * st) == 0)
          res++;
        mnoz++;
      }
      printf("%d\n", res);
    }
  }
  if (!ok || sq[0] != sq[1]) {
    printf("0\n");
  }
  return 0;
}
