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 10285 Longest Run on a Snowboard - 记忆化搜索

    记忆化搜索,完事... Code /** * UVa * Problem#10285 * Accepted * Time:0ms */ #include<iostream> #includ ...

  2. CSS形变与动画

    形变 2D形变 matrix(): 以一个含六值的(a,b,c,d,e,f)变换矩阵的形式指定一个2D变换,相当于直接应用一个[a,b,c,d,e,f]变换矩阵 translate(): 指定对象的2 ...

  3. 分布式系统一致性协议--Paxos算法

    Paxos: Paxos算法背景介绍: Paxos算法是分布式技术大师Lamport提出的,主要目的是通过这个算法,让参与分布式处理的每个参与者逐步达成一致意见.用好理解的方式来说,就是在一个选举过程 ...

  4. 【附3】springboot源码解析 - 构建SpringApplication

    package com.microservice.framework; import org.springframework.boot.SpringApplication; import org.sp ...

  5. java 如果仅输出一位和要输出多位格式的输出问题,利用boolean值.

    package com.ykmimi.testtest; /** * 第七周第二题,来自网络 */ import java.util.Scanner; public class NumberPerfe ...

  6. UVa 10817 校长的烦恼

    https://vjudge.net/problem/UVA-10817 题意: 某校有m个教师和n个求职者,需讲授s个课程,已知每人的工资c和能教的课程集合,要求支付最少的工资使得每门课都至少有两名 ...

  7. codeforces 766E Mahmoud and a xor trip

    题目链接:http://codeforces.com/problemset/problem/766/E 大意,给出一个$n$个点的树,每个点都有一个权值,令$Disx$为$u$到$v$路径上的异或和求 ...

  8. python 插入查找

    def interpolation_search(data,val): low= high=len(data)- print('查找过程中......') : mid=low+int((val-dat ...

  9. 常规css,js引入

    php // css,js用 $this->assign('MODULE_NAME',MODULE_NAME); $this->assign('ACTION_NAME',ACTION_NA ...

  10. Django 综合篇

    前面,已经将Django最主要的五大系统介绍完毕,除了这些主要章节,还有很多比较重要的内容,比如开发流程相关.安全.本地化与国际化.常见工具和一些框架核心功能.这些内容的篇幅都不大,但整合起来也是Dj ...