SGU 113
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的更多相关文章
- Nearly prime numbers - SGU 113(素数)
题目大意:判断一个数是否是两个素数的乘积,如果是,输出Yes,否则No. 分析:先打表求出来一部分素因子,用素数对素数判定还是比较快的. 代码如下: ========================= ...
- SGU 113.Nearly prime numbers
水一个代码: #include <iostream> using namespace std; int n, a; bool ok; bool prime (int x) { ; i * ...
- SGU题目总结
SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- NYOJ题目113字符串替换
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAHvCAIAAAA930vtAAAgAElEQVR4nO3dPVLjysIG4G8T5CyE2A ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- 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 ...
随机推荐
- Nginx初始化过程总结
对于Nginx这样一个模块化的服务器,看代码是最好的理解方式了.再此通过读main() 函数来简述一下Nginx的初始化过程: 这就是整个main函数的执行过程:
- poj 2312 Battle City
题目连接 http://poj.org/problem?id=1840 Battle City Description Many of us had played the game "Bat ...
- Android UmengShareSDK第三方登录
Android UmengShareSDK 第三方登录- 今天就不废话了,集成平台第三方登录.市面上集成平台有shareSDK 和 Ument两种,shareSDK的ipa和服务好些,如果自己研究会很 ...
- 1 通过JNI混合使用Java和C++ -----> 操作字符串
JNI(Java Native Interface)是Java语言的一部分,可以访问非Java语言编写的程序,也可以用于在C++程序中执行Java代码. 步骤: 1> 编写带有native声明 ...
- 安装MSITVPN连接的时候弹出:需要(未知)上的文件'MSITVPN.bmp。
使用 msitvpn 连接microsoft 公司内网,在安装msitvpn的时候突然弹出一个对话框提示需要msitvpn.bmp 文件,找了很久都没找到解决问题方案. 最后只能猜测是不是和用户的权限 ...
- linux 简单的DMA例程
一个简单的使用DMA 例子 示例:下面是一个简单的使用DMA进行传输的驱动程序,它是一个假想的设备,只列出DMA相关的部分来说明驱动程序中如何使用DMA的. 函数dad_transfer是设置DMA对 ...
- ASP.NET Web API 实例
ASP.NET Web API 入门大杂烩 创建Web API解决方案,命名为VCoinWebApi,并且创建了同名的Project,然后,创建一个Empty Project:Models,创建一个W ...
- 子网划分与CIDR(斜杠加数字的表示与IP 的关系)(改进)
子网和CIDR 将常规的子网掩码转换为二进制,将发现子网掩格式为连续的二进制1跟连续0,其中子网掩码中为1的部份表示网络ID,子网掩中为0的表示主机ID.比如255.255.0.0转换为二进制为1 ...
- TFS更新
我们小组决定将对学长的代码提出改进意见贯穿整个任务的整个过程,随时更新任务进度. 共计预计项目时间为58小时. 每个人都能够达到5到10小时的工作量.
- 第一个完整的cppunit单元测试程序
在极限编程中,测试程序本应该在编写主程序之前就要写好,然后将写好的类程序放在测试程序中进行测试,但考虑到项目中需求文档等并未将接口定义好,我无从开始,而且,自己对单元测试也是刚刚熟悉,需要一边写测试程 ...