其他分享
首页 > 其他分享> > 20201017 day38 模拟(十一)

20201017 day38 模拟(十一)

作者:互联网

1

problem

对有限集合\(A\),存在函数\(f:N→A\)具有下述性质:若\(|i-j|\)是素数,则\(f(i)≠f(j),N=\{1,2,…\}\).求有限集合A的元素的最少个数.

solution

【引理】\(\forall p\ge 2\),若\(p\)为质数,则\(p=4n+1\)或\(p=4n+3,n\in \mathbb N\)
证明:①所有大于2的素数都是奇数
②\(4n+1,4n+3\)表示了所有的奇数
【证明】
\(1,3,6,8\)中每两个数的差为素数,所以\(f(1),f(3),f(5),f(8)\)互不相同,\(|A|≥4\).
另一方面,令\(A=\{0,1,2,3\}\).对每一自然数\(n\),令\(f(n)=n\operatorname{mod} 4\),则在\(f(i)=f(j)\)时,\(|i-j|\)被4整除.所以不被4整除时,\(f(i)\neq f(j)\),因而\(|i-j|\)是质数。
因而\(f\)是满足条件的函数,A的元素个数最少为4.

code

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
long long read(){
	int a=0,op=1;char c=getchar();
	while(c>'9'||c<'0') {if(c=='-') op=-1;c=getchar();}
	while(c>='0'&&c<='9'){a*=10,a+=c^48,c=getchar();}
	return a*op;
}
int n, ans = 0x3f3f3f3f, now, col[10], ans_col[10];
int main()
{
	scanf("%d", &n);
	if (n <= 6)
	{
		printf("%d\n", (n + 1) / 2);
		for (int i = 1; i <= n; i++)
			printf("%d ", (i + 1) / 2);
	}
	else
	{
		puts("4");
		for (int i = 1; i <= n; i++)
			printf("%d ", 1 + (i & 3));
		return 0;
	}
	return 0;
}

标签:day38,20201017,质数,long,4n,素数,整除,include,模拟
来源: https://www.cnblogs.com/liuziwen0224/p/20201017day38-001.html