You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
470 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
int p, q, res;
/*
4 7
:4*7-4-7=17
*/
bool dfs(int x) {
if (x == 0) return true;
if (x >= p && dfs(x - p)) return true;
if (x >= q && dfs(x - q)) return true;
return false;
}
int main() {
scanf("%d %d", &p, &q);
for (int i = 1; i <= 1000; i++)
if (!dfs(i)) res = i;
printf("%d\n", res);
return 0;
}