CF 230B. T-primes

server/2025/3/18 21:09:01/

题目

time limit per test:2 seconds;memory limit per test:256 megabytes

We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.

You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

Input

The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012).

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.

Output

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

Examples

Input

3
4 5 6

Output

YES
NO
NO

Note

The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".

 

 思路

根据题目,一个数如果是完全平方数,并且这个数的平方根是质数,那就符合 Т -prime 的定义,这是可以
证明的。可以用欧拉筛法判断质数,或者埃氏筛法。不知为何,在 CF 上提交之后,用埃氏筛法甚至比欧
拉筛法要快,可能是没有想到优化的方法 , 或者某些操作耗费了时间。

 

代码

python">import math
def euler_sieve(n):prime = [True] * (n+1)prime[0] = prime[1] = Falsep = 2while p*p <= n:if prime[p]:for i in range(p*p, n+1, p):prime[i] = Falsep += 1return prime# 判断一个数是否为素数
def is_prime(n):if n < 2:return Falsereturn prime[n]t=int(input())
nums=list(map(int,input().split()))
n=max(nums)
prime = euler_sieve(int(math.sqrt(n))+1)
# print(prime)
for x in nums:r=int(x**0.5)if r**2!=x:print("NO")else:if is_prime(r):print("YES")else:print("NO")
python">import math
def judgePri(N):isPrime = [True] * (N+1)    #用于标注一个整数是否为质数primes = [] #用于存放素数,一开始是空的cnt = 0isPrime[0]=isPrime[1] = False# M=int(math.sqrt(N))for i in range(2,N):if isPrime[i]:  #如果i为质数,就添加到primes中primes.append(i)cnt += 1    #标记primes中元素的个数for j in range(cnt):temp = i * primes[j]if temp >= N:   #若合数i * primes[j]越界,则不作处理,结束本轮遍历breakisPrime[temp] = Falseif i % primes[j] == 0:breakreturn isPrimet=int(input())
nums=list(map(int,input().split()))
n=max(nums)
isPrime= judgePri(int(math.sqrt(n))+1)
# print(prime)
for x in nums:r=int(math.sqrt(x))if r**2!=x:print("NO")else:if isPrime[r]:print("YES")else:print("NO")


http://www.ppmy.cn/server/176051.html

相关文章

时间有限,如何精确设计测试用例?5种关键方法

精确设计测试用例能够迅速识别并修复主要缺陷&#xff0c;确保产品质量&#xff0c;降低后期维护成本&#xff0c;并通过专注于核心功能来提升用户体验&#xff0c;为项目的成功奠定坚实基础。若未能精确设计测试用例&#xff0c;可能会导致关键功能测试不充分&#xff0c;使得…

Pandas与PySpark混合计算实战:突破单机极限的智能数据处理方案

引言&#xff1a;大数据时代的混合计算革命 当数据规模突破十亿级时&#xff0c;传统单机Pandas面临内存溢出、计算缓慢等瓶颈。PySpark虽能处理PB级数据&#xff0c;但在开发效率和局部计算灵活性上存在不足。本文将揭示如何构建PandasPySpark混合计算管道&#xff0c;在保留…

定义模型生成数据表

1. 数据库配置 js import { Sequelize, DataTypes } from sequelize; // 创建一个 Sequelize 实例&#xff0c;连接到 SQLite 数据库。 export const sequelize new Sequelize(test, sa, "123456", { host: localhost, dialect: sqlite, storage: ./blog.db })…

第十五届蓝桥杯C/C++B组拔河问题详解

解题思路 这道题目的难点在于枚举所有区间&#xff0c;并且区间不能重合&#xff0c;那么这样感觉就很难了。但是用下面这种方法就会好很多。 我们只需要将左边的所有区间的各种和放在一个set中&#xff0c;然后我们在枚举右边的所有区间的和去和它进行比较&#xff0c;然后…

DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加列宽调整功能,示例Table14_13可展开行的固定表头表格

前言:哈喽,大家好,今天给大家分享一篇文章!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加列宽调整功能,示例Table14_13可展开行的固…

Java---网络初识

本文章用于理解网络中的各个关键字 1.IP地址 &#xff1a; 用于标识网络主机&#xff0c;和其他网络设备的网络地址 比如我们发快递时&#xff0c;需要知道对方的地址才能将包裹发送给他 格式&#xff1a; IPv4&#xff1a; IP地址是32位二进制数&#xff0c;如&#xff1…

淘宝/天猫获得淘宝商品评论 API 返回值说明

item_review-获得淘宝商品评论 taobao.item_review 公共参数 名称类型必须描述keyString是调用key&#xff08;必须以GET方式拼接在URL中&#xff09;secretString是调用密钥api_nameString是API接口名称&#xff08;包括在请求地址中&#xff09;[item_search,item_get,item…

ZooKeeper的五大核心作用及其在分布式系统中的关键价值

引言 在分布式系统的复杂架构中&#xff0c;协调多个节点的一致性、可靠性和高可用性始终是技术挑战的核心。​Apache ZooKeeper作为业界广泛采用的分布式协调服务&#xff0c;凭借其简洁的树形数据模型&#xff08;ZNode&#xff09;和高效的原子广播协议&#xff08;ZAB&…