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 ...
随机推荐
- MT【314】正切比值
(05复旦)已知三角形$\Delta ABC$满足$\tan A:\tan B:\tan C=1:2:3$,求$\dfrac{AC}{AB}$____ 解答:设$x=tan A$,利用恒等式$\tan ...
- Pthread 用法笔记
什么是线程? 从技术上讲,一个线程被定义为一个独立的指令流. 一个进程可以包含一个或多个线程. 线程操作包括线程创建,终止,同步(连接,阻塞),调度,数据管理和进程交互. 进程内的所有线程共享: 相同 ...
- ExKMP(Z Algorithm) 讲解
目录 问题引入 CaiOJ 1461 [EXKMP]最长共同前缀长度 算法讲解 匹配过程 next 的求解 复杂度证明 代码解决 一些例题 UOJ #5. [NOI2014]动物园 CF1051E V ...
- python学习 day13 装饰器(一)&推导式
装饰器&推导式 传参位置参数在前,关键词参数在后 函数不被调用内部代码不被执行 函数在被调用的时候,每次都会开辟一个新的内存地址,互不干扰 #经典案例 def func(num): def i ...
- LVM备份(1)-创建LVM逻辑卷
LV(Logical Volume) - 逻辑卷 VG(Volume Group) - 卷组 PV(Physical Volume) - 物理卷 1.查看分区信息:fdisk -l 可看到磁盘大小为1 ...
- postgres 基本操作
登陆: $ psql -U <user> -d <dbname> 数据库操作: $ \l //查看库 $ \c <dbname> //切换库 // ...
- 关于学习Linux的基本命令操作
常用的Linux 命令 scp root/1.txt root@127.0.0.1:/home rpm 安装软件 systemctl start service 启动服务 systemctl res ...
- 树状数组BIT
模板1 #include<iostream> #include<cstdio> using namespace std; int n, m, c[500010]; inline ...
- C++-int类型整数超出范围后的处理
最近做了一道题目: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: ...
- python学习02
python的数据类型 程序=数据类型+算法 1.数据类型:数据型,字符串,列表list,字典dict,set集合(),tuple元组() 1)数据型 int,整数型,理论上是无限大,不过受到机器内存 ...