【Acwing】第 95 场周赛

这两段代码分别解决两个问题。第一段程序计算两个数之间的最大差值;第二段实现了一个简单的线性筛法来找出素数,并判断一个数是否为素数的平方,用于检查输入数的因子特性。
摘要由CSDN通过智能技术生成

4873. 简单计算

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;
LL a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	LL ans = max(abs(a-c),abs(b-d));
	cout<<ans;
	return 0;
}

4874. 约数
一个数若只有三个因数,则它必定是一个素数的平方。
使用线性筛

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;
//简单线性筛
int n;
int p[N],cnt = 0;
bool st[N]; 
int main()
{
	memset(st,true,sizeof st);
	st[1] = false;
	for(int i = 2;i <= 1000000;i++){
		if(st[i]) p[++cnt] = i;
		for(int j = 1;p[j] * i <= 1000000;j++){
			st[p[j] * i] = false;
			if(i % p[j] == 0) break;
		}
	}
	cin>>n;
	while(n--){
		LL x;
		cin>>x;
		LL t = sqrt(x);
		if(t*t == x && st[x]) puts("YES");
		else put("NO");
	}
	return 0;
}

4875. 整数游戏


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值