瞎搞瞎搞...
题意不用说了是中文,但是文字编码是GB2312的,如果用一般浏览器默认的Unicode会乱码。
妈蛋感觉不会做有木有-。-
于是可以非常暴力地猜一猜。。。
首先,显然由于x,y>=2,那么1一定不能被表示出来,也就是一定存在不能被表示出来的数。其次,我们对10以内的组合猜一猜,数的表示范围开大一点,随便开一个10086好了。然后我们检测1~10086可否被表示出来。表示的本质就是某个数必须是ax+by(a,b为非负整数)的倍数。我们对每组(x,y)检测该范围下不能被表示的最大整数,如下:
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 10;
const int UP = 10086;
bool ok[UP];
int judge(int x, int y) {
memset(ok, false, sizeof(ok));
for (int i = 1; x * i < UP; ++i) ok[x * i] = true;
for (int i = 1; y * i < UP; ++i) ok[y * i] = true;
for (int a = 1; a * x < UP; ++a) {
for (int b = 1; a * x + b * y < UP; ++b) {
int t = a * x + b * y;
for (int i = 1; t * i < UP; ++i) ok[t * i] = true;
}
}
//printf("(%d, %d): ", x, y);
for (int i = UP - 1; i > 0; --i) {
if (!ok[i]) {
//printf("%d\n", i);
return i;
}
}
}
int main() {
for (int x = 2; x < MAX; ++x) {
for (int y = x; y < MAX; ++y) {
printf("(%d,%d)->%d\n", x, y, judge(x, y));
}
}
return 0;
}
打表结果是这样的:
可以很容易地看出,如果(x,y)不互质(gcd(x,y)>1)那么后面的数都会相当大。由此我们可以得出一个猜想:gcd(x, y) != 1时,结果一定存在,否则就是Inf。
于是我们可以加上gcd再次打表:
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 10;
const int UP = 10086;
bool ok[UP];
int judge(int x, int y) {
memset(ok, false, sizeof(ok));
for (int i = 1; x * i < UP; ++i) ok[x * i] = true;
for (int i = 1; y * i < UP; ++i) ok[y * i] = true;
for (int a = 1; a * x < UP; ++a) {
for (int b = 1; a * x + b * y < UP; ++b) {
int t = a * x + b * y;
for (int i = 1; t * i < UP; ++i) ok[t * i] = true;
}
}
//printf("(%d, %d): ", x, y);
for (int i = UP - 1; i > 0; --i) {
if (!ok[i]) {
//printf("%d\n", i);
return i;
}
}
}
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
int main() {
for (int x = 2; x < MAX; ++x) {
for (int y = x; y < MAX; ++y) {
if (gcd(x, y) == 1) {
printf("(%d,%d)->%d\n", x, y, judge(x, y));
}
}
}
return 0;
}
这次的结果是:
YY一下可以看出,ans = x * y - (x + y).于是得解:
#include <cstdio>
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
int main() {
int a, b;
while (~scanf(" %d %d", &a, &b) && a) {
if (gcd(a, b) == 1) {
printf("%lld\n", (long long)a * b - a - b);
} else {
puts("Inf");
}
}
return 0;
}