B. T-primes
/*
PROBLEMSSUBMITSTATUSSTANDINGSCUSTOM TEST
B. T-primes
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. Sample test(s)
input
3
4 5 6
output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
*/
#include <iostream>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 1003
bool isprime( __int64 n)
{
for( __int64 i=; i<=sqrt((float)n); i++)
if(n%i==)
return ;
return ;
}
int main()
{
__int64 num,n,tmp;
scanf("%I64d",&num);
while(num--) {
scanf("%I64d",&n);
if(n==)
{
printf("NO\n");
continue;
}
tmp=sqrt((float)n);
if(tmp*tmp==n)
{
if(isprime(tmp))
printf("YES\n");
else
printf("NO\n");
}
else
{
printf("NO\n");
}
}
return ;
}
B. T-primes的更多相关文章
- [LeetCode] Count Primes 质数的个数
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- 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 ...
- HDU 4715:Difference Between Primes
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- hdu 4715 Difference Between Primes
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...
- hdu 5104 Primes Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5104 Primes Problem Description Given a number n, ple ...
随机推荐
- 2PC
两阶段提交()Two-Phase Commit):是计算机网络尤其是在数据库领域内,为了使基于分布式系统架构下的所有节点在进行事务处理过程中能够保持原子性和一致性而设计的一种算法.通常,二阶段提交协议 ...
- visual studio 一些小技巧 整理
本博客将会陆续的整理一些作者在实际开发中的一些小技巧,一些挺有意思的东西,将会持续更新, 如果有问题,可以加群讨论,QQ群:592132877 #warning的使用 #warning 的意思是在程序 ...
- 细说C语言的优先级和结合性
Table0. 为什么要掌握优先级1. 优先级1.1 优先级图表1.2 运算符实例1.3 优先级顺口溜2. 结合性3. 参考资料 写代码的时候,常会翻看的一个表就是“c语言运算符优先级表”.c的运算符 ...
- 模块(Modules)
一.引入模块 模块:当编写更大的应用程序时,所有的代码肯定会分成多个文件,这样便于维护,另外已经编写好的函数和对象在被多个程序中使用时,不用把函数和对象拷贝到每个程序中. 模块支持以上功能,在Pyth ...
- 对集合应用符号 | & ^ -
s1 = set('abc') s2 = set('abs') # 在s1而不在s2 print s1 - s2 # set(['c']) # 在s1或者s2 print s1 | s2 # set( ...
- Android:数据持久化(1/2)文件、SharedPreferences
Summary 持久化的3种方法: 普通文件:I/O流操作文件: SharedPreferences:XML文件,通过key-value pair的形式存储数据: SQLite:Android自带数据 ...
- python动态给对象或者类添加方法
参考:http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object In Python, there is ...
- groovy && java 混编 gradle 配置
参考配置: apply plugin: "application" apply plugin: "java" apply plugin: "groov ...
- 系列文章--Enterprise Library文章总结
自Enterprise Library 1.1 推出以来,Terry写了一系列的关于Enterprise Library的文章,其中得到了很多朋友的支持,在这里一并表示感谢.为了方便大家的阅读,这里我 ...
- Google Chrome 总提示flash插件过期,用命令行模式解决
目标那改成:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --args --allow-outdate ...