import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long a = sc.nextInt(); long b = sc.nextInt(); long t = sc.nextInt(); long lcm = a / gcd(a, b) * b; long total = t % lcm; if (lcm < t) { total += lcm; } long min = Long.MAX_VALUE; if (b > a) { long tmp = b; b = a; a = tmp; } for (int i = 0; i * a < total; i++) { min = Math.min(min, (total - i * a + b - 1) / b * b - total + i * a); } min = Math.min(min, (total + a - 1) / a * a - total); System.out.println(t + min); } static long gcd(long x, long y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); } } }