Description
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?≤?10000),showing how many numbers are in the array.

The next line contains n space-separated integers xi (1?≤?xi?≤?10^12).

Output
Print one line: The number of T-primes number

Sample Input
 Copy sample input to clipboard
3
4 5 6
Sample Output
1
Hint
Please use long long instead of int for any Xi.

The given test has three numbers.

The first number 4 has exactly three divisors — 1, 2 and 4.

The second number 5 has two divisors (1 and 5),

The third number 6 has four divisors (1, 2, 3, 6),

hence the answer for them is 1 (only the number 4 is T-primes number).

思路:题就是判断一个数是否仅含有3个因子,其实也就是除了1和它自身外,还存在另一个因子。如果找到这个另外的因子就输出yes,否则为no。数据范围1e15,不小了 ,

一个数n是T素数,一定是1,n,sqrt(n),且sqrt(n)为素数

也就是如果一个数是素数的平方,那么这个数有且仅有三个因子。

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j;
long long a,b;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a;
b = sqrt(a);
for(j=2; j*j <= b; j++) {
if(b%j == 0){
break; //判断根号后的a即b是不是素数
}
}
if(j*j > b && b*b == a && a>1){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
return 0;
}

  

Sicily T-primes的更多相关文章

  1. sicily 1259. Sum of Consecutive Primes

    Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...

  2. [LeetCode] Count Primes 质数的个数

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  3. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  4. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  5. projecteuler Summation of primes

    The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...

  6. leetcode-Count Primes 以及python的小特性

    题目大家都非常熟悉,求小于n的所有素数的个数. 自己写的python 代码老是通不过时间门槛,无奈去看了看大家写的code.下面是我看到的投票最高的code: class Solution: # @p ...

  7. Count Primes - LeetCode

    examination questions Description: Count the number of prime numbers less than a non-negative number ...

  8. [leetcode] Count Primes

    Count Primes Description: Count the number of prime numbers less than a non-negative number, n click ...

  9. Count Primes

    Count the number of prime numbers less than a non-negative number, n public int countPrimes(int n) { ...

  10. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

随机推荐

  1. ☆ [HNOI2012] 永无乡 「平衡树启发式合并」

    题目类型:平衡树启发式合并 传送门:>Here< 题意:节点可以连边(不能断边),询问任意两个节点的连通性与一个连通块中排名第\(k\)的节点 解题思路 如果不需要询问排名,那么并查集即可 ...

  2. <数据结构基础学习>(二)简单的时间复杂度分析

    一.简单的复杂度分析 O(1) O(n) O(logn) O(logn) O(n^2) 大O描述的是算法的运行事件和输入数据之间的关系 Eg: 数组求和 public static int sum(i ...

  3. Meterpreter提权详解

      0x01 Meterpreter自动提权 1.生成后门程序 我们在kali的命令行下直接执行以下命令获得一个针对windows的反弹型木马: msfvenom -p windows/meterpr ...

  4. 缓存服务—Redis

    Redis 简介Redis 是一个开源(BSD 许可)的.内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 为什么要用 Redis 在高并发场景下,如果需要经常连接结果变动频繁的数据库, ...

  5. I/O模型之一:Unix的五种I/O模型

    目录: <I/O模型之一:Unix的五种I/O模型> <I/O模型之二:Linux IO模式及 select.poll.epoll详解> <I/O模型之三:两种高性能 I ...

  6. vsftpd启动问题简记

    centos7 能以ipv6方式启动,启动只需修改配置如下 如需同时启动到ipv4跟ipv6,需拷贝配置文件,一份配置中只监听ipv4,一份配置中只监听ipv6 centos6中无法启动到ipv6,错 ...

  7. [物理学与PDEs]第1章习题14 求解 rot 方程

    设向量函数 ${\bf B}(x,y,z)=(B_x,B_y,B_z)$ 在 $z\neq 0$ 时具有一阶连续偏导数, 在 $z=0$ 时具有第一类间断, 且 $$\bex \Div{\bf B}= ...

  8. idea+maven+ssm搭建boot_crm项目遇到的问题

    使用idea+maven+ssm搭建一个boot_crm项目,遇到的问题如下: 1.环境搭建好了,相关配置文件都配置好了,也部署到了tomcat,但是无法启动首页. 通过百度,google找到了,原因 ...

  9. mui弹出菜单

    详细操作见代码: <!doctype html> <html> <head> <meta charset="UTF-8"> < ...

  10. 6.linux安装tomcat

    1.下载安装包 https://tomcat.apache.org/download-80.cgi       2.用 WinSCP 将本地的安装包 上传到 linux 服务器中   3.解压安装包( ...