sgu 113 求破

Kylehz 2013-07-10 11:00:12
题目

Problem DescriptionNearly
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



#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int a[100],b[40000];
int main()
{
int n,i,j,m;
b[0]=1;
b[1]=1;
for(i=2;i<40000;i++)b[i]=0;
for(i=2;i<40000;i++){
for(j=i*2;j<40000;j+=i)b[j]=1;//0代表素数
}

while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
m=0;
for(j=2;j<a[i]/2+1;j++)
{



if(a[i]%j==0&&b[j]==0&&b[a[i]/j]==0)
{
m=1;
break;
}
}
if(m==1)printf("Yes\n");
else printf("No\n");
}
}
return 0;
}



提交后一直是Runtime Error 求破
...全文
41 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,661

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧