首页 > 其他 > 详细

hdu1164 Eddy's research I

时间:2014-04-06 02:40:30      阅读:540      评论:0      收藏:0      [点我收藏+]

Eddy‘s research I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5890    Accepted Submission(s): 3516


Problem Description
Eddy‘s interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can‘t write program, so Eddy has to ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor .

 

Input
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.
 

Output
You have to print a line in the output for each entry with the answer to the previous question.
 

Sample Input
11 9412
 

Sample Output
11 2*2*13*181
 


//============================================================================
// Name        : Math_hdu1164.cpp
// Author      : vit
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;
//start
#define MAX 65536

bool Visit[MAX];
int prime[MAX];

int p = 0;
void Prime()//可做求质数的模板
{
    memset(Visit,true,sizeof(Visit));
    Visit[0] = Visit[1] = 0;
    for(int i = 2; i < MAX; ++i)
    {
        if(Visit[i])
        {
            prime[p] = i;
            p++;
            for(int j = i; j < MAX; j+=i)
                Visit[j] = false;
        }
    }
}
//end

int main() {
	int i;
	int n;
	Prime();
	while(cin >> i){
		if(Visit[i])
			printf("%d\n",i);
		else{
			n = 0;
			while(i != 1){
				if(i % prime[n] == 0){
					cout << prime[n];
					i = i / prime[n];
					if(i != 1)
						cout << "*";
				}
				else
					n++;
			}
			cout << endl;
		}

	}


	return 0;
}


hdu1164 Eddy's research I,布布扣,bubuko.com

hdu1164 Eddy's research I

原文:http://blog.csdn.net/svitter/article/details/22996463

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