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. 【UR #7】水题走四方

    题目描述 今天是世界水日,著名的水题资源专家蝈蝈大臣发起了水题走四方活动,向全世界发放成千上万的水题. 蝈蝈大臣是家里蹲大学的教授,当然不愿意出门发水题啦!所以他委托他的助手欧姆来发. 助手欧姆最近做 ...

  2. vue-cli3.0 gui(一)

    vue-cli3.0 gui 安装: npm i core-js -g:用于JavaScript的模块化标准库. npm i -g @vue/cli:vue的脚手架工具 运行: vue ui:运行vu ...

  3. Shell脚本之grep

    1. 过滤空行   grep -v ^$

  4. Linux系统在线安装、启动 redis

    环境: Linux系统:VMware 14 中 CentOS 7 64 位 redis版本:redis-stable.tar.gz(当前版本是:redis-cli 4.0.9) 一.Linux在线安装 ...

  5. 查找命令which、whereis、locate

      1.find 最常用和最强大的查找命令.它能做到实时查找,精确查找,但速度慢. find的使用格式如下: $ find [指定目录] [指定条件] [指定动作] 指定目录:是指所要搜索的目录和其子 ...

  6. SpringBoot系列: Pebble模板引擎语法介绍

    本文基于Pebble官方文档, 对pebble的语法做一些介绍. ===============================Pebble 官方资料========================= ...

  7. JGUI源码:从头开始,建一个自己的UI框架(1)

    开篇 1.JGUI是为了逼迫自己研究底层点的前端技术而做的框架,之前对web底层实现一直没有深入研究,有了技术瓶颈,痛定思痛从头研究, 2.虽然现在vue技术比较火,但还在发展阶段,暂时先使用JQue ...

  8. [物理学与PDEs]第1章第8节 静电场和静磁场 8.1 静电场

    1. 静电场: 由静止电荷产生的稳定电场. 2. 此时, Maxwell 方程组为 $$\bex \Div{\bf D}=\rho_f,\quad \rot{\bf E}={\bf 0}. \eex$ ...

  9. 二维、三维 Laplace 算子的极坐标表示

    (1) 设 $(r,\theta)$ 是 $\bbR^2$ 的极坐标, 即 $$\bex x=r\cos\theta,\quad y=r\sin \theta. \eex$$ 证明 Laplace 算 ...

  10. MongoDB and GUI 管理界面

    MongoDB https://www.mongodb.com/ MongoDB AtlasDatabase as a Service The best way to deploy, operate, ...