数论 CF230B T-primes
CF230B T-primes
我们知道质数是只有两个不同的正数因数的正整数。相似的,我们把一个正整数 t 叫做 T质数,如果 t 恰好有三个不同的正整数因数。
你被给了一个含有 n 个正整数的数组。你要给其中所有的数判断它是否是 T质数。
可以知道一个质数的完全平方数有且只有三个因子。
然后这题就水了。
线性筛出1到$\sqrt{a_i} $的素数,判断就行了。
code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define int long long
using namespace std;
inline int read(){
int sum=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){sum=(sum<<1)+(sum<<3)+ch-'0'; ch=getchar();}
return sum*f;
}
int n,tot;
int a[100017];
int prime[1000017];
int isprime[1000017];
void Euler(){
memset(isprime,1,sizeof isprime);
isprime[1]=0;
for(int i=2;i<=1000000;i++){
if(isprime[i])
prime[++tot]=i;
for(int j=1;j<=tot&&i*prime[j]<=1000000;j++){
isprime[i*prime[j]]=0;
if(i%prime[j]==0)break;
}
}
}
signed main(){
n=read(); Euler();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=n;i++){
int tmp=sqrt(a[i]+0.5);
if(isprime[tmp]){
if(tmp*tmp==a[i])puts("YES");
else puts("NO");
}
else puts("NO");
}
return 0;
}
数论 CF230B T-primes的更多相关文章
- UVA 10168 Summation of Four Primes(数论)
Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler p ...
- Leetcode 204 Count Primes 数论
题意:统计小于n的质数个数. 作为一个无节操的楼主,表示用了素数筛法,并没有用线性素数筛法. 是的,素数筛法并不是该题最佳的解法,线性素数筛法才是. 至于什么是素数筛法,请百度吧. class Sol ...
- SPOJ AMR11E Distinct Primes 基础数论
Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger i ...
- Lucas的数论题解
Lucas的数论 reference 题目在这里> < Pre 数论分块 默认向下取整时. 形如\(\sum\limits_{i=1}^n f\left( \frac{n}{i}\righ ...
- ACM HDU Primes(素数判断)
Problem Description Writea program to read in a list of integers and determine whether or not eachnu ...
- RSA算法原理——(2)RSA简介及基础数论知识
上期为大家介绍了目前常见加密算法,相信阅读过的同学们对目前的加密算法也算是有了一个大概的了解.如果你对这些解密算法概念及特点还不是很清晰的话,昌昌非常推荐大家可以看看HTTPS的加密通信原理,因为HT ...
- 【HDU】2866:Special Prime【数论】
Special Prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 51nod1238. 最小公倍数之和 V3(数论)
题目链接 https://www.51nod.com/Challenge/Problem.html#!#problemId=1238 题解 本来想做个杜教筛板子题结果用另一种方法过了...... 所谓 ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
随机推荐
- java实现文件的拷贝以及文件的删除
/** * 将文件拷贝到指定目录 * @param oldAddress 文件所在目录(文件的全路径) * @param newAddress 指定目录(包含复制文件的全名称) * @throws E ...
- Openssl errstr命令
一.简介 errstr命令用于查询错误代码 二.语法 errstr [-stats] <errno> 选项 -stats:打印哈希表状态 errno:错误号 三.实例 1.查看错误信息 : ...
- leetCode--towSum
题目链接:https://leetcode.com/problems/two-sum/description/ 此题的意思是:给定一个target值,从给定的数组中找两个数,使得这两个数的和==tar ...
- 点云数据保存为pcd文件_pcd_write.cpp
#include <iostream>#include <pcl/io/pcd_io.h>#include <pcl/point_types.h> int main ...
- LWIP协议栈2-
->->->
- 设计模式12: Proxy 代理模式(结构型模式)
Proxy 代理模式(结构型模式) 直接与间接 人们对于复杂的软件系统常常有一种处理手法,即增加一层间接层,从而对系统获得一种更为灵活.满足特定需求的解决方案.如下图,开始时,A需要和B进行3次通信, ...
- 编写高质量代码改善C#程序的157个建议——建议112:将现实世界中的对象抽象为类,将可复用对象圈起来就是命名空间
建议112:将现实世界中的对象抽象为类,将可复用对象圈起来就是命名空间 在我们身边的世界中,对象是什么?对象就是事物,俗称“东西”.那么,什么东西算得上是一个对象呢?对象有属性.有行为.以动物为例,比 ...
- socket API详解
send函数 int send( SOCKET s, const char FAR *buf, int len, int flags ); 不论是客户还是服务器应用程序都用send函数来向 ...
- CodeForces 327E Axis Walking(状压DP+卡常技巧)
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...
- JavaScript - this详解 (一)
侃侃JavaScript中的this this为何如此多变? this总是跟它的执行上下文有关,而在JavaScript总会有开辟新的执行上下文的东西,比如函数,所以,this才如此的变化. 执行环境 ...