【瞎搞】toj3001

8 篇文章 0 订阅

瞎搞瞎搞...

题意不用说了是中文,但是文字编码是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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值