Day 21 B. T-primes

2023-11-10

Problem
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”.

题目大致意思为:给你一个数 判断这个数的因子个数是否为3个

#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#define ll long long
using namespace std;
//如果要判断一个数的因子个数是否为三个 
//那么这个数除了自身和1以外 
//必须是一个完全平方数并且开根号后的这个数是质数
bool Isprime(int a)
{
	if (a < 2)
	{
		return false;
	}
	for (int i = 2; i <= sqrt(a); i++)
	{
		if (a % i == 0)
		{
			return false;
		}
	}
	return true;
}
int main()
{
	int x;
	cin >> x;
	for (int i = 0; i < x; i++)
	{
		ll a;
		ll b;
		cin >> a;
		b = sqrt(a);
		if (b * b == a)
		{
			if (Isprime(sqrt(a)))
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Day 21 B. T-primes 的相关文章

随机推荐

  • rem的使用方式

    rem是什么 rem是指相对于根元素的字体大小的单位 在日常开发过程中我们通常把根元素 html body 的字体设置为10px 方便于我们计算 此时子元素的1rem就相当于10px rem与em的区别 各自的优缺点 em子元素字体大小的e
  • CVPR 2019 论文大盘点—人体姿态篇

    CV君盘点了CVPR 2019 中有关人体姿态的论文 其中研究 3D人体姿态估计的论文最多 有 11 篇 研究 2D 姿态估计的 7 篇 姿态迁移 2 篇 人体图像生成 1 篇 人体捕捉 2 篇 另外还有2篇创建了新的基准数据集 姿态估计是
  • python云图

    安装相关插件 python3 m pip install jieba wordcloud matplotlib import matplotlib pyplot as plt import jieba from wordcloud impo
  • 【Spring Boot】【前后端分离】后端接口返回结果统一封装

    文章目录 创建 SpringBoot 项目 封装返回结果 实现返回对象的自动封装 处理异常 测试 最近在尝试使用前后端分离的模式写一个简单的个人博客 遇到接口数据返回结构的问题 在网上查了一圈 发现了一个很好用的方法 在复现的过程中也遇到了
  • 算法设计与分析课后总结

    算法设计与分析课后总结 算法设计与分析 第1章 算法设计基础 课后习题 第二章算法分析基础 课后习题 1 考虑下面算法 回答下列问题 算法完成什么功能 算法的基本语句时什么 基本语句执行了多少次 2 分析以下程序段中基本语句的执行次数 要求
  • 100天精通Python(可视化篇)——第92天:Pyecharts绘制炫酷柱状图、条形图实战大全

    文章目录 专栏导读 1 基础柱状图 2 旋转x轴标签 3 旋转坐标轴 4 添加坐标轴名称 5 添加标记点 6 添加标注线 7 添加数据 8 添加自定义背景图 9 堆叠柱状图 10 柱状图与折线图组合 11 三维柱状图 12 水平滑动 鼠标滚
  • 包、模块、函数的关系结构

    三者关系 python中程序的结构是由包 模块 函数 类大致构成 其关系如下 package module function 模块定义与调用 1 python中一个 py文件都可以是一个module module可以有函数 类 代码组成 如
  • 使用python解决中英混合参考文献中et al 和等的问题

    这个代码使用zipfile将docx进行解压 然后操作document xml文件 找到中文中的et al之后替换为 等 然后再压缩为docx import zipfile import re import os import shutil
  • curl服务器文件,curl 向远程服务器传输file文件

    public function upload 获取上传文件信息 文件名称以自己实际上传文件名称为准 fileinfo FILE filename 请求参数 依据商户自己的参数为准 requestParam version requestPa
  • 声网(agora)音视频通话sdk—微信小程序demo

    首先需要注册一个声网账号 注册成功后创建项目 appid是指声网项目的appid 后续会在小程序的配置文件中用到 微信小程序接入视频通话 需要声网给开通小程序的权限 给声网邮箱发送邮件 注明开通微信小程序接入权限 并给发送appid app
  • Python代码扫描:企业级代码代码安全漏洞扫描Bandit

    目录 什么是Bandit 特点 安装 配置 配置Bandit Pycharm配置外置工具 使用实践 命令行参数 检查单个文件 检查整个目录 PyCharm中对单个文件或者项目目录的扫描 一个使用案例 应用场景 总结 参考资料 注意 后续技术
  • js DOM

    DOM Document Object Model HTML 和 XML 文档的编程接口 通过 DOM JavaScript 能够访问和改变 HTML 文档的所有元素 1 查找 通过 id 查找 HTML 元素 div div 2 通过标签
  • Paper and Codes Leaderboard

    目录 介绍 模型入选标准 1 目标检测 Paper and Codes for COCO by 2023 3 31 COCO FPS Models by 2023 02 18 Look at Batch Size 2 图像分类 ImageN
  • 【Backbone: MLP-Mixer】MLP-Mixer: An all-MLP Architecture for Vision

    Abstract CNN和attention based结构很棒 但不是必须的 本文提出MLP Mixer 一种基于多层感知机 MLPs 的框架 包含两种layers 1 channel mixing MLPs 应用在image patch
  • C++(30)——lambda表达式原理及应用

    lambda lambda这个词起源于数学上的 在C 中利用lambda表达式 可以方便的定义和创建匿名函数 lambda可以看做函数对象的升级版 改进了函数对象以下的缺点 使用在泛型算法中的参数传递的过程中 比较性质 自定义操作 优先级队
  • J2EE之自定义MVC框架知识(中篇)

    J2EE之自定义MVC框架知识 中篇 文章目录 J2EE之自定义MVC框架知识 中篇 前言 1 优化中央控制器中的action容器 使其加载变成可配置的 1 1 编写 xml文件 config xml 1 2 导入XML建模相关的类 Act
  • INNO setup 制作安装包

    1 获取SQLserver安装路径vardbpath string rtn boolean rtn RegQueryStringValue HKEY LOCAL MACHINE SOFTWAREMicrosoftMSSQLServerSet
  • 95-38-150-Buffer-CompositeByteBuf

    文章目录 1 概述 2 继承关系 1 概述 CompositeByteBuf实际就是个ByteBuf的包装器 它将多个ByteBuf组合成一个集合 然后对外提供统一的ByteBuf接口 2 继承关系
  • 对象,我遇见了你

    对象 什么是对象 对象属性 Object assign Object create Object is Object keys Object values Object entries Object fromEntries Object t
  • Day 21 B. T-primes

    Problem We know that prime numbers are positive integers that have exactly two distinct positive divisors Similarly we l