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
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; int n; bool judge(int x) {
int sum = ;
int t;
for(int i = ; i * i <= x; i++) {
if(x % i == ) {
sum++;
t = i; }
} return sum == && ((x / t == t) || x / t % t != ) ;
}
int main()
{ scanf("%d",&n); for(int i = ; i <= n; i++) {
int ch;
scanf("%d",&ch);
if(judge(ch)) printf("Yes\n");
else printf("No\n");
}
return ;
}
6

Sample Output

Yes

 易知,我们要寻找的数除1 与自身外其他的因子数必然不超过2,假设有两个因子,则其中一个因子必然不能整除另一个因子。

SGU 113的更多相关文章

  1. Nearly prime numbers - SGU 113(素数)

    题目大意:判断一个数是否是两个素数的乘积,如果是,输出Yes,否则No. 分析:先打表求出来一部分素因子,用素数对素数判定还是比较快的. 代码如下: ========================= ...

  2. SGU 113.Nearly prime numbers

    水一个代码: #include <iostream> using namespace std; int n, a; bool ok; bool prime (int x) { ; i * ...

  3. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  4. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  5. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  6. NYOJ题目113字符串替换

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAHvCAIAAAA930vtAAAgAElEQVR4nO3dPVLjysIG4G8T5CyE2A ...

  7. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  8. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  9. SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...

随机推荐

  1. 【J2EE】Java连接SQL Server 2000问题:“com.microsoft.sqlserver.jdbc.SQLServerException:用户'sa'登录失败。该用户与可信SQL Server连接无关联”

    1.问题现象 E:\JSP\HibernateDemo\HibernateDemoProject\src\sine>java ConnectSQLServerConnect failed!com ...

  2. Java入门到精通——基础篇之static关键字

    一.概述        static 关键字是声明静态变量,静态方法用的.static的含义是属于类且不属于类对象的变量和函数. 二.static的产生.         在创建对象的时候除非用new ...

  3. VS2012 常用web.config配置解析之自定义配置节点

    在web.config文件中拥有一个用户自定义配置节点configSections,这个节点可以方便用户在web.config中随意的添加配置节点,让程序更加灵活(主要用于第三方插件的配置使用) 自定 ...

  4. ExtJS FormPanel不执行校验

    经检查问题原因在于使用了 validator 属性. 使用validator属性,必须添加返回值.不添加返回值,就会出现FormPanel不执行校验的问题.

  5. [shell基础]——cut命令

    cut命令常见选项

  6. 论单页Web应用和RESTful架构

    单页Web应用 概述 单页Web应用并不是突然诞生的一门新技术,而是web展示的一种新的尝试.它将所有的动作局限于一个Web页面,在加载站点首页的时候就加载站点需要的JavaScript和CSS.单页 ...

  7. 目前国内外主流的linux发行版本

    1.linux其实是基于unix发展而来的,还有mac os也是类unix操作系统 2.目前主流的linux发行版本主要有:红帽系列(中国大陆,美洲地区,发源于美国),suse系列(欧洲地区流行,发源 ...

  8. Min Stack

    Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constan ...

  9. LintCode-Implement Queue by Stacks

    As the title described, you should only use two stacks to implement a queue's actions. The queue sho ...

  10. C++输出四则运算设计题的思路

    一,(1)题目避免重复:使用srand(seed)函数进行随机化,随seed的不同,可以产生不同的随机数二,(1)控制数量:输入变量n控制三,(1)控制是否有乘除:(chengchu=0,没有乘除:c ...