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. uva 1658 Admiral - 费用流

    vjudge传送门[here] 题目大意:给一个有(3≤v≤1000)个点e(3≤e≤10000)条边的有向加权图,求1~v的两条不相交(除了起点和终点外没有公共点)的路径,使权值和最小. 正解是吧2 ...

  2. Duilib Edit编辑框禁止输入中文的方法

    转载:http://www.myexception.cn/vc-mfc/300749.html 编辑框是供用户输入的,但有时候我们要限制用户输入的内容,比如我们不让用户输入中文,只能输入字符和数字,因 ...

  3. Python3基础 file open+write 对不存在的txt进行创建与写入

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. Python3基础 __repr__ 实例对象的名字,可以显示信息

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. JavaScript 题目

    1. ],b=a; b[]=; console.log(a+b); a=[], b=a, b=[]; console.log(a+b); 2.快速排序法 var quickSort = functio ...

  6. POJ 1270 Following Orders(拓扑排序)题解

    Description Order is an important concept in mathematics and in computer science. For example, Zorn' ...

  7. spring boot 修改Tomcat端口

    package com.tsou.Controller; import org.springframework.boot.*; import org.springframework.boot.auto ...

  8. ajax实现highchart与数据库数据结合完整案例分析(三)---柱状折线图

    作者原创,未经博主允许,不可转载 在前面分析和讲解了用java代码分别实现饼状图和折线图,在工作当中,也会遇到很多用ajax进行异步请求 实现highchart. 先展示一下实现的效果图: 用ajax ...

  9. nginx缓存功能的设置

    首先用的缓存是proxy_cache. 在http段里加入下列几句: [plain] view plain copy   proxy_connect_timeout 5; proxy_read_tim ...

  10. GATK--使用转载

    http://blog.sciencenet.cn/blog-1469385-819498.html 文章目录 一.准备工作 二.流程概览 三.流程 首先说说GATK可以做什么.它主要用于从seque ...