6th Jilin Province Collegiate Programming Contest - Mar 20, 2012——Problem A: Welcome 2012

问题描述:

http://acm.jlu.edu.cn/joj/showproblem.php?pid=2771&contestid=199

Welcome to 2012 Jilin Province Collegiate Programming Contest.

Year 2012 is a special year, and the 2012 is also a special number. For example, 
2012= 2*2*503, here 2 and 503 are both prime number.
As we know, A prime number (or a prime) is a natural number greater than 1 that 
has no positive divisors other than 1 and itself.
This time, we should find out the numbers that can be divided like 2012. That is to 
say, for a positive number n, can be  written n=p1*p1*p2, here p1 and  p2 are 
different prime numbers.
Input
This problem has no input
Output
You should output all the numbers that satisfied the rules before. There numbers 
are increasing order and less than 3000.
Sample Output
12
18
……
2012
……
Not all the numbers are listed in the sample. There are just some examples. The 

ellipsis expresses what you should calculate.

答案代码:

#include<iostream>
#include<cmath>
using namespace std;

//判断素数函数
bool isPrime(int n)
{
	int i=2;
	int upper=sqrt(float(n));
	while(i<=upper)
	{
		if(n%i==0)
		{
			return false;
		}
		i++;
	}

	return true;
}

//主函数
int main()
{
	int sn=12;
	while(sn<=3000)
	{
		if((sn%(2*2)==0)&&(isPrime(sn/(2*2))))
		{
			cout<<sn<<endl;
		}
		int upper=sqrt(float(sn));
		for(int i=3;i<upper;i=i+1)
		{
			if(isPrime(i)&&(sn%(i*i)==0)&&(i!=(sn/(i*i)))&&(isPrime(sn/(i*i))))
			{
				cout<<sn<<endl;
			}
		}

		sn++;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值