#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int count = 0;
  if (a.find(b) != -1 || b.find(a) != -1)
    for (int i = 1; i <= a.length(); i++) {
      if (a.length() % i == 0 && b.length() % i == 0) {
        bool pass = true;
        for (int j = 0; j < a.length() - i; j += i) {
          if (a.substr(j, i) != a.substr(j + i, i)) {
            pass = false;
          }
        }
        for (int j = 0; j < b.length() - i; j += i) {
          if (b.substr(j, i) != b.substr(j + i, i)) pass = false;
        }
        if (pass) count++;
      }
    }
  cout << count;
  return 0;
}
