Codeforces1174B分类讨论 C素数打表

https://codeforces.com/contest/1174/problem/B

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;	//1e9
typedef pair<ll,ll> pll;
const int maxn=4e5+5;
const int INF=0x3f3f3f3f;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,m,a[maxn];

int num=0,cnt=0;
int odd=0,even=0;	//4 7 2  7 4 2  2 4 7
int main()
{	//全为奇数 任意两个求和为偶数 不交换 全为偶数 不交换 
	cin>>n;
	rep(i,1,n){
		cin>>a[i];
		if(a[i]&1)
			odd++;
		else
			even++;
			
	}
	if(odd && even)	//既有奇数 又有偶数 一定可以交换成递增形式 
		sort(a+1,a+n+1);
	rep(i,1,n)
	{
		cout<<a[i];
		if(i!=n)
			cout<<" ";
		else
			cout<<endl;
	}
	return 0;
}

https://codeforces.com/contest/1174/problem/C
两个不同的质数肯定互质。
两个不同的合数如果没有公共质因子,也互质。
也就是说只有素数的倍数之间不互质 值可以相等
素数筛的过程中给素数赋予新值,素数的倍数赋予和这个素数相同的值
比如位置 2,4 (i,j)不互质 所以值相等

无公因子的合数 值肯定不相等

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;	//1e9
typedef pair<ll,ll> pll;
const int maxn=4e5+5;
const int INF=0x3f3f3f3f;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,m,a[maxn],vis[maxn];

int num=0,cnt=0;
void init(){
	for(int i=2;i<=n;i++){
		if(vis[i]==0)
		{
			a[i]=++cnt;
			vis[i]=1;
		}
		for(int j=i+i;j<=n;j+=i){
			if(!vis[j]){
				vis[j]=1;
				a[j]=cnt;
			}
		}	
	}
}//两个质数互质 两个合数无公因子也互质4,9 只有素数的倍数不互质 
int main()
{	
	cin>>n;
	init();
	rep(i,2,n)
	{
		cout<<a[i];
		if(i!=n)
			cout<<" ";
		else
			cout<<endl;
	 } 
	return 0;
}

互质的让值不相等 不互质的值肯定相等
无公因子的合数互质
4,9 追溯到2,3 值 1 ,2 值肯定不相等
素数的倍数不互质 值令相等

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值