113. Nearly prime numbers

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

Nearly prime number is an integer positive number for which it is possible to find such primes P1 and P2 that given number is equal to P1*P2. There is given a sequence on N integer positive numbers, you are to write a program that prints “Yes” if given number is nearly prime and “No” otherwise.

Input

Input file consists of N+1 numbers. First is positive integer N (1£N£10). Next N numbers followed by N. Each number is not greater than 109. All numbers separated by whitespace(s).

Output

Write a line in output file for each number of given sequence. Write “Yes” in it if given number is nearly prime and “No” in other case.

Sample Input

1
6

Sample Output

Yes

思路:nearly prime数只能有两个质因数
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,num;
bool nearlyprime(){
int cnt=0;
int r=sqrt((double)num);
if((num&1)==0){
while((num&1)==0){
num>>=1;
cnt++;
if(cnt>2)return false;
}
}
for(int i=3;i<=r;i+=2){
if(num%i==0){
while(num%i==0){
num/=i;
cnt++;
if(cnt>2)return false;
}
}
}
if(num!=1)cnt++;
return cnt==2;
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&num);
if(nearlyprime())puts("Yes");
else puts("No");
}
return 0;
}

  

快速切题 sgu113 Nearly prime numbers 难度:0的更多相关文章

  1. POJ 2739 Sum of Consecutive Prime Numbers 难度:0

    题目链接:http://poj.org/problem?id=2739 #include <cstdio> #include <cstring> using namespace ...

  2. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697 ...

  3. HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )

    How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  4. HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)

    Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...

  5. POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25225 ...

  6. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

  7. poj 2739 Sum of Consecutive Prime Numbers 尺取法

    Time Limit: 1000MS   Memory Limit: 65536K Description Some positive integers can be represented by a ...

  8. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. C# 取form表单的数据

    //key代表form表单中html元素的name属性值 public static string StringForm(string key) { string result = null; res ...

  2. tensorflow拟合随机生成的三维数据【学习笔记】

    平台信息:PC:ubuntu18.04.i5.anaconda2.cuda9.0.cudnn7.0.5.tensorflow1.10.GTX1060 作者:庄泽彬(欢迎转载,请注明作者) 说明:感谢t ...

  3. Linux-进程间的通信-信号集函数【转】

    我们已经知道,我们可以通过信号来终止进程,也可以通过信号来在进程间进行通信,程序也可以通过指定信号的关联处理函数来改变信号的默认处理方式,也可以屏蔽某些信号,使其不能传递给进程.那么我们应该如何设定我 ...

  4. P3466 [POI2008]KLO-Building blocks

    目录 题目 思路 错误 代码 题目 luogu csdn好像限制了展开博客次数,真的好xx 思路 显然一段区间内的值一定是他的中位数 少一点比多一点好 然后就可以枚举区间了 区间答案为 val[mid ...

  5. ubuntu 安装 ftp服务

    1. 更新源列表 ---> sudo apt-get update 2. 安装vsftpd ---> sudo apt-get install vsftpd (安装) ----> s ...

  6. java Request 获得用户IP地址

    public static String getIpAddress(HttpServletRequest request) { String ip = request.getHeader(" ...

  7. 如何在Twitter开发者平台上注册自己的应用

    1.打开twitter的官网https://dev.twitter.com,如果还没有注册账号的,需要注册账号,已经注册账号的,请先登录:2.选择其中的My apps,如下图: 3.进去界面,选择Cr ...

  8. 使用JavaScript / JQuery导出 html table 数据至 Excel 兼容IE/Chrome/Firefox

    function fnExcelReport() { var tab_text="<table border='2px'><tr bgcolor='#87AFC6'> ...

  9. 【Python】【元编程】【三】【元类】

    '''# str. type 和 LineItem 是object 的子类 str. object 和 LineItem 是 type 的实例,因为它们都是类object 类和 type 类之间的关系 ...

  10. shell 加法计算

    Shell 相加目前发现有 3 种写法: 1. a=10 b=20 c=`expr ${a} + ${b}` echo "$c" 2. c=$[ `expr 10 + 20` ] ...