Codeforces 230B
来源:互联网 发布:js包装函数是什么 编辑:程序博客网 时间:2024/04/30 18:58
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integertТ-prime, ift 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.
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 integersxi (1 ≤ xi ≤ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use thecin,cout streams or the%I64d specifier.
Print n lines: the i-th line should contain "YES" (without the quotes), if numberxi is Т-prime, and "NO" (without the quotes), if it isn't.
34 5 6
YESNONO
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<cmath>
#include<cstring>
# define m 1000005
using namespace std;
bool pri[m];
void getpri()
{
int i,j;
pri[0]=pri[1]=0;
pri[2]=1;
for(i=3;i<=m;++i) pri[i]=i%2==0?0:1;
int t=sqrt(m);
for(i=3;i<=t;++i)
{
if(pri[i])
{
for(int j=i*i;j<=m;j+=2*i) pri[j]=0;
}
}
}
int main()
{
long long n,a,t;
getpri();
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>a;
t=sqrt(a);
if(t*t==a&&a!=1&&pri[t]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
- Codeforces 230B
- codeforces-230B-T-primes
- codeforces div2 round#230 B
- CodeForces 230B T-primes
- [Codeforces] 230B - T-primes
- codeforces-230B T-primes
- Codeforces-230B-T-primes
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- codeforces #230 (Div. 2) B(简单数学)
- Codeforces Round #230 (Div. 1)B,C
- codeforces 230/B 素数变形计
- codeforces T-primes 230 B 素数题解
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- 软考之文法
- 前端面试题汇总(二)含解答
- UOJ 58 [WC2013]糖果公园
- 天天写业务代码,如何成为技术大牛?
- 地域性与忽略大小写的字符串比较
- Codeforces 230B
- jzoj 4812. 【NOIP2016提高A组五校联考2】string 排列组合+乘法逆元
- nginx.org的Using nginx as HTTP load balancer页面翻译
- Leetcode 286. Walls and Gates (Google面试题 BFS,记忆化搜索)
- 前端人员必须会的jsonp!
- 如何从技术菜鸟成为“10倍效率”开发者
- NRF24L01双向传输数据
- Android学习笔记-事件处理机制
- Android——View的工作原理(一)