27 lines
470 B
C++
27 lines
470 B
C++
|
|
#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;
|
|||
|
|
}
|