#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int g;
int gcd(int x, int y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
bool compare(int x) {
  for (int i = 0; i <= g - x; i += x)
    for (int j = 0; j < x; j++)
      if (s1[i + j] != s1[j]) return false;
  return true;
}
int main() {
  cin >> s1 >> s2;
  int l1 = s1.length(), l2 = s2.length();
  g = gcd(l1, l2);
  for (int j = 0; j < g; j++)
    if (s1[j] != s2[j]) {
      cout << 0;
      return 0;
    }
  for (int i = 0; i <= l1 - g; i += g)
    for (int j = 0; j < g; j++)
      if (s1[i + j] != s1[j]) {
        cout << 0;
        return 0;
      }
  for (int i = 0; i <= l2 - g; i += g)
    for (int j = 0; j < g; j++)
      if (s2[i + j] != s2[j]) {
        cout << 0;
        return 0;
      }
  int ans = 0;
  for (int i = 1; i * i <= g; i++) {
    if (g % i == 0) {
      if (compare(i)) ans++;
      if (i != g / i and compare(g / i)) ans++;
    }
  }
  cout << ans << "\n";
}
