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. Vivado寄存器初始值问题

    前言 本复位只针对Vivado中的寄存器复位. 什么时候需要复位?到底要不要复位?怎么复位?复位有什么卵用? 该复位的寄存器需要复位,复位使得寄存器恢复初始值,有的寄存器并不需要复位(数据流路径上). ...

  2. SpringMvc的自动装箱和GET请求参数可以为自定义对象的思考

    在我的概念里边,GET请求需要加上注解@RequestParam,然后它的参数类型只能是 基本数据类型 或者 基本数据类型的包装类,比如:@RequestParam String name(默认是必传 ...

  3. (转)Spring事务管理详解

    背景:之前一直在学习数据库中的相关事务,而忽略了spring中的事务配置,在阿里面试时候基本是惨败,这里做一个总结. 可能是最漂亮的Spring事务管理详解 https://github.com/Sn ...

  4. 使用Webstorm建立vue.js工程并添加vuetify组件

    .. .. .. ..等待安装完 ..生成的目录结构 ..打开Webstorm的终端 ..最后出现 ..回到工程目录,右键 ..显示npm面板,点击serve运行 .. ..打开[貌似跟以前不一样了. ...

  5. Linux 下 boost 库的安装,配置个人环境变量

    部分引自: https://blog.csdn.net/this_capslock/article/details/47170313 1. 下载boost安装包并解压缩到http://www.boos ...

  6. Kubernetes集群调度器原理剖析及思考

    简述 云环境或者计算仓库级别(将整个数据中心当做单个计算池)的集群管理系统通常会定义出工作负载的规范,并使用调度器将工作负载放置到集群恰当的位置.好的调度器可以让集群的工作处理更高效,同时提高资源利用 ...

  7. shell 通过EOF在脚本中输入需要的用户名或密码

    参考地址:https://www.cnblogs.com/liyuanhong/p/10390786.html expect使用参考:https://www.cnblogs.com/liyuanhon ...

  8. go 的包

  9. tensorflow Method源码阅读之 fully_connected

    https://www.tensorflow.org/api_docs/python/tf/contrib/layers/fully_connected fully_connected: 1.先根据权 ...

  10. 🍓rem单位在Chrome中字体大小异常 🍓

    这是一个很少出现,而一旦出现就让人头疼难当的bug.....网上资料比较少. 解决:https://oss.so/article/87 即为html标签设置-webkit-text-size-adju ...