#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int gcd(int a, int b) {
 	while (b) b ^= a ^= b ^= a %= b;
	return a;
}

int f(int x, int d) {
 	vector<int> v;
	for (int i = 2; i <= x; i++) {
	 	while (x % i == 0) {
	 	 	v.push_back(i);
			x /= i;
		}
	}
	int ans = 0;
	for (int l = 0; l < (int)v.size(); l++) {
	 	int r = l;
		int cur = 1;
		while (r < (int)v.size() && 1LL * cur * v[r] <= d) {
		 	cur *= v[r++];
		}
		if (r == l) return 1e9;
		l = r - 1;
		ans++;
	}
	return ans;
}
int main() {
 	freopen("operation.in", "r", stdin);
	freopen("operation.out", "w", stdout);
	int a, b, d;
	cin >> a >> b >> d;
	int g = gcd(a, b);
	int ans = f(a / g, d) + f(b / g, d);
	if (ans >= 1e9) ans = -1;
	cout << ans << endl;
	return 0;
}