首页 > 其他 > 详细

HDU 1164

时间:2014-09-07 22:20:45      阅读:254      评论:0      收藏:0      [点我收藏+]

因为规模小,使用试除法即可

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int Maxn=100;
int prime[Maxn];

int main(){
	int n,m;
	while(scanf("%d",&n)!=EOF){
		int l=(int)sqrt(n*1.0);
		int tot=0; m=n;
		for(int i=2;i<=l;i++){
			if(m%i==0){
			//	cout<<i<<endl;
				while(m%i==0){
					prime[tot++]=i;
					m/=i;
				}
			}
		}
		if(m>1)
		prime[tot++]=m;
		printf("%d",prime[0]);
		for(int i=1;i<tot;i++)
		printf("*%d",prime[i]);
		printf("\n");
	}
	return 0;
}

  

HDU 1164

原文:http://www.cnblogs.com/jie-dcai/p/3960803.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!