• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

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
6

Sample Output

Yes

Author : Michael R. Mirzayanov
Resource : PhTL #1 Training Contests
Date : Fall 2001
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 #include <sstream>
 5 #include <memory>
 6 #include <algorithm>
 7 using namespace std;
 8 int prv[50005], pri[50005];
 9 int main(){
10     int k = 0;
11     for (int i = 2; i < 41000;i++)
12     if (!prv[i])
13     for (int j = i*i; j < 41000; j += i)
14         if (!prv[j])prv[j] = 1;
15         for (int i = 2; i < 41000; i++)if (!prv[i])pri[k++] = i;
16     int n;
17     cin >> n;
18     while (n--){
19         int x,t;
20         cin >> x;
21         if (x <= 0){ cout << "No\n"; continue; }
22         int flag = 0;
23         for (int i = 0; i < k; i++)
24             while (x % pri[i] == 0)x = x / pri[i], flag++;
25             if (x!=1)flag++;
26         if (flag==2)printf("Yes\n"); else printf("No\n");
27     }
28 }
View Code
posted @ 2014-01-30 03:44  HaibaraAi  阅读(101)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3