#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int xx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int yy[] = {1, -1, 0, 0, 1, -1, -1, 1};
double PI = 3.1415926535897932384626433832795;
const long long oo = (long long)1e9 + 1;
const double eps = 1e-9;
const long long mod = 1000000009;
string a, b;
bool good(int l, string s) {
  for (int i = 0; i < ((long long)s.size()); i++) {
    if (a[i % l] != s[i]) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> a >> b;
  int res = 0;
  for (int i = 1; i <= min(((long long)a.size()), ((long long)b.size())); i++) {
    if (((long long)a.size()) % i == 0 && ((long long)b.size()) % i == 0 &&
        good(i, a) && good(i, b))
      res++;
  }
  cout << res << endl;
  return 0;
}
