#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main(void) {
  string s1, s2;
  cin >> s1 >> s2;
  if (s1.size() < s2.size()) swap(s1, s2);
  int n = s1.size(), m = s2.size(), g = gcd(n, m), i, ans = 0, j;
  if (s1.substr(0, m) != s2) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 1; i <= g; i++) {
    if (g % i == 0) {
      bool ne = false;
      for (j = 0; j < n; j += i) {
        if (s1.substr(j, i) != s1.substr(0, i)) {
          ne = true;
          break;
        }
      }
      if (!ne) ans++;
    }
  }
  cout << ans << endl;
}
