230B - T-primes

链接:

https://codeforces.com/problemset/problem/230/B

题意:

给定n个数,只且仅有三个因数的输出YES,其他输出NO;

输入

3
4 5 6

输出量

YES
NO
NO

解:

三个数,其中1和数字本身占一个,另一个只能是该数开根号,所以平方数为其中一个条件,同时发现计算平方数的因数个数也会超时,发现如果根号数为素数时,有且仅有三个因数,因为素数不能拆(乘法

实际代码:

#include<iostream>
#include<cmath>
using namespace std;
typedef long long int ll;
bool ss(int a)
{
	//cout<<"a"<<a<<endl;
	int sq=sqrt(a);
	if(a>=2)
	{
	for(int i=2;i<=sq;i++)
	{
		if(a%i==0)
		{
			return false;
		}
	}
	//cout<<"duia"<<a<<endl;
	}
	else return false;
	return true;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ll t;
		cin>>t;
		ll a=sqrt(t);
		if(a*a==t)
		{
			if(ss(a)) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else cout<<"NO"<<endl;
	}
}

限制:

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值