CF 230B. T-primes

news/2025/3/18 3:58:03/

题目

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/news/1579971.html

相关文章

麒麟系统使用-安装 SQL Developer

文章目录 前言一、基础准备1.基本环境2.相关包下载 二、进行相关配置1.配置JAVA2.配置SQL Developer 总结 前言 作为我国自主研发的操作系统&#xff0c;麒麟系统在使用时需要考虑安装相应的app。尽管麒麟系统是基于linux开发&#xff0c;可由于版本的一些差异&#xff0c;麒麟…

JVM常用概念之超态虚拟调用

问题 超态虚拟调用是什么? 基础知识 大部分认为超态调用是非常糟糕的&#xff0c;主要是因为超态调用会调用慢路径&#xff0c;并且无法享受编译器优化&#xff0c;那OpenJDK可以取消超态调用吗?那在发生超态调用时我们可以做什么呢? 实验 源码 import org.openjdk.jm…

【图片批量转换合并PDF】多个文件夹的图片以文件夹为单位批量合并成一个PDF,基于wpf的实现方案

项目背景: 多个图片分布在不同文件夹,如何以文件夹为单位批量合并成一个PDF,还要保证文件夹里面图片大小和顺序 实现功能: 1、单张图片的转换PDF:一张图临时转一下 2、多张图片转换成PDF:多张图单独转成PDF 3、多级目录多张图转换成PDF:多级目录多张图单独转成多个PDF…

塔能IVO-SCY智能机箱:点亮智慧城市的电力“智慧核芯”

在智慧城市建设的宏大征程中&#xff0c;稳定且智能的电力供应犹如坚固基石&#xff0c;支撑着各类设备高效、稳定地运行。塔能科技的IVO-SCY智能机箱&#xff0c;凭借其卓越的电源管理系统&#xff0c;当之无愧地成为了整个智慧城市电力保障体系中的“智慧心脏”&#xff0c;源…

数据传输对象 DTO

1. DTO 数据传输对象&#xff08;DTO, Data Transfer Object&#xff09;是一种设计模式&#xff0c;用于在不同系统或应用层之间封装和传输数据。它通常用于解耦领域模型&#xff08;如数据库实体&#xff09;和外部接口&#xff08;如API请求/响应&#xff09;&#xff0c;避…

Chrome 扩展开发API实战:Runtime(八)

1. 引言 在开发 Chrome 扩展程序时&#xff0c;chrome.runtime API 是一个至关重要的接口。它提供了与扩展程序生命周期管理、消息传递、环境信息获取、与原生应用通信等相关的功能。本文将详细介绍 chrome.runtime API 的所有方法和事件&#xff0c;并通过示例代码演示如何在…

蓝桥杯_数字诗意_java

问题描述 在诗人的眼中&#xff0c;数字是生活的韵律&#xff0c;也是诗意的表达。 小蓝&#xff0c;当代顶级诗人与数学家&#xff0c;被赋予了"数学诗人"的美誉。他擅长将冰冷的数字与抽象的诗意相融合&#xff0c;并用优雅的文字将数学之美展现于纸上。 某日&…

Unity学习日志番外:简易行为树

Unity简单行为树 参考与代码来自b站-ANVER-大佬教学视频以下都是一种固定模板结构&#xff0c;便于外部以及新项目引用。1.BehaviorTree类2.Node类3.composite4.Sequence5.Selector6.Task7.Blackboard8.实例①兔子行为树②巡逻任务③探测萝卜任务③吃萝卜任务 个人对行为树的理…