Sicily T-primes
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的更多相关文章
- sicily 1259. Sum of Consecutive Primes
Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...
- [LeetCode] Count Primes 质数的个数
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- 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 ...
- leetcode-Count Primes 以及python的小特性
题目大家都非常熟悉,求小于n的所有素数的个数. 自己写的python 代码老是通不过时间门槛,无奈去看了看大家写的code.下面是我看到的投票最高的code: class Solution: # @p ...
- Count Primes - LeetCode
examination questions Description: Count the number of prime numbers less than a non-negative number ...
- [leetcode] Count Primes
Count Primes Description: Count the number of prime numbers less than a non-negative number, n click ...
- Count Primes
Count the number of prime numbers less than a non-negative number, n public int countPrimes(int n) { ...
- 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 ...
随机推荐
- shell 基础(一)
废话少说 往下看 1. 查看 Shell Shell 是一个程序,一般都是放在/bin或者/user/bin目录下,当前 Linux 系统可用的 Shell 都记录在/etc/shells文件中./e ...
- Java8学习笔记(一)--Lambda表达式
两个概念 函数式接口 函数式接口就是只显式声明一个抽象方法的接口.为保证方法数量不多不少,java8提供了一个专用注解@FunctionalInterface,这样,当接口中声明的抽象方法多于或少于一 ...
- Java基础 -- 访问控制权限
一 包:库单元 假设我们存在两个类名相同的类,如果没有一定的措施对其进行区分,就会无法区别到底使用的是哪一个类.因此java引入了包来进行名字空间管理. 包(类库)包含有一组类,这些类在单一的名字空 ...
- Harbo1.5.2离线搭建
环境说明 操作系统版本:Centos7.5 docker版本:docker-ce 17.03.2 harbor版本:v1.5.2 docker-compose: 1.22.0 基础环境搭建 系统优化 ...
- JS正则与PHP正则
- [物理学与PDEs]第1章第7节 媒质中的 Maxwell 方程组 7.2 媒质交界面上的条件
通过 Maxwell 方程组的积分形式易在交界面上各量应满足交界面条件: $$\beex \bea \sez{{\bf D}}\cdot{\bf n}=\omega_f,&\sex{\omeg ...
- Vue Material
Material Design是什么? https://www.zhihu.com/topic/20005114/top-answers 我们挑战自我,为用户创造了崭新的视觉设计语言.与此同时,新的设 ...
- tensorflow 模型保存和加载
使用 tf.train.Saver 保存:tf.train.Saver.save(sess, save_path, global_step=None, latest_filename=None, me ...
- Luogu P4321 随机漫游
期望DP要倒着推 Luogu P4321 题意 LOJ #2542 不一定是树,询问点不一定均为1 $Solution$ 设计一个巧妙的DP状态 设$ F(S,x)$表示当前在点$ x$已经走遍了$ ...
- springMVC中controller的几种返回类型
==网文1,还不错,感觉比较老旧springMVC中controller的几种返回类型 - CSDN博客http://blog.csdn.net/qq_16071145/article/details ...