题目:

Problem D

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
代码:
//该题与模板相比就只有一个地方要处理一下,就是组成拆分数的素数因子有可能是几个相同的因子
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 65535
int prime[MAX+5];
void fun()
{
    memset(prime,0,sizeof(prime));
    for(int i=2;i<=MAX/2;i++)
    {
        for(int j=i+i;j<=MAX;j+=i)
        {
            prime[j]=1;
        }
    } 
}
int main()
{
    fun();
    int x;
    while(scanf("%d",&x)!=EOF)
    {
        int i=2;
        int c=1;
        int t=x; 
        while(i<=x)
        {
             if(t%i==0 && !prime[i])
             {
                 if(c==1)
                 {
                     printf("%d",i);
                     c++;
                 }
                 else
                 {
                     printf("*%d",i);
                 }
                 t=t/i;//刚开始t/i被我写成t/2,结果一直不对 ,哎。。。又粗心了 
             }
             else
             {
                 i++;
             }
        }
        printf("\n");
    }
    system("pause");
    return 0;
}
posted on 2011-05-31 22:36  枫叶飘泪  阅读(214)  评论(0编辑  收藏  举报