#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 = 1; i * i <= x; i++) if (x % i == 0) v.push_back(i), v.push_back(x / i);
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	vector<int> dp(v.size(), 1e9);
	dp[0] = 0;
	for (int i = 0; i < (int)v.size(); i++) {
	 	for (int j = i + 1; j < (int)v.size() && v[j] / v[i] <= d; j++) {
	 	 	if (v[j] % v[i] == 0) dp[j] = min(dp[j], dp[i] + 1);
		}
	}
	return dp.back();
}
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;
}