#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int len, l1, l2;
unsigned long long int hv;
unsigned long long int h[1000005], p[1000005], h1[1000005];
int ans, res, pos;
unsigned long long int hashing(int pos) {
  return h[len] - (h[len - pos] * p[pos]);
}
set<int> diiv;
set<int>::iterator it;
bool solve(int pos) {
  int i, t;
  t = max(l1, l2);
  for (i = pos; i <= t; i += pos) {
    if (i <= l1) {
      if (i == pos) {
        if (h[pos] != h[pos]) return 0;
      } else {
        if (h[pos] != h[i] - (h[i - pos] * p[pos])) return 0;
      }
    }
    if (i <= l2) {
      if (i == pos) {
        if (h[pos] != h1[i]) return 0;
      } else {
        if (h[pos] != h1[i] - (h1[i - pos] * p[pos])) return 0;
      }
    }
  }
  return 1;
}
int main() {
  int i, sq;
  cin >> s1 >> s2;
  l1 = s1.size();
  l2 = s2.size();
  len = max(l1, l2);
  s1 = '#' + s1;
  s2 = '#' + s2;
  h[0] = 1;
  hv = 5;
  p[1] = 5;
  for (i = 2; i <= len; i++) p[i] = p[i - 1] * hv;
  h[1] = s1[1] - 'a';
  for (i = 2; i <= l1; i++) {
    h[i] = h[i - 1] * hv + (s1[i] - 'a');
  }
  h1[1] = s2[1] - 'a';
  for (i = 2; i <= l2; i++) {
    h1[i] = h1[i - 1] * hv + (s2[i] - 'a');
  }
  len = min(l1, l2);
  diiv.insert(1);
  for (i = 2; i <= len; i++) {
    if (l1 % i == 0 and l2 % i == 0) diiv.insert(i);
  }
  ans = 0;
  for (it = diiv.begin(); it != diiv.end(); it++) {
    pos = *it;
    if (solve(pos)) {
      ans++;
    }
  }
  cout << ans << endl;
}
