Eddy's research I

来源:互联网 发布:sql2005打开1433端口 编辑:程序博客网 时间:2024/04/25 07:23

Eddy's research I

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 13   Accepted Submission(s) : 10

Font: Times New Roman | Verdana | Georgia

Font Size:  

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

119412

Sample Output

112*2*13*181

//大概意思是给你一个数,分解成几个素数之和,首先打一个素数表从2--70000;把所有的素数全部求出来;然后用个for循环去匹配把每一个素数全部存入一个数组;最重要的是要处理可能出现两个相同的素数;代码中巧妙的用了i--这个;对于9412这个样例来说;首先i=0 a[i]=2 ;9412除以2余数为0 进入if循环i--为-1;再i++为0;继续4076除以2余数依旧为0;第三次除以2的时候发现余数不为0;不进入if;所以这就实现了储存两个相同的素数;

#include <iostream>
#include <math.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
int fun(int n){
int t,i;
if(n==1)
return 0;
t=(int)sqrt(1.0*n);
for(i=2;i<=t;i++)
if(n%i==0)
return 0;
return 1;
}
int main ()
{
    int a[66000],b[66000];
    int an,bn,i,n;
    for(i=2,an=0; i<66000; i++)
    {
        if(fun(i))
            a[an++]=i;
    }
    while(cin>>n)
    {


            bn=0;
            for(i=0; a[i]<=n; i++)
            {
                if(n%a[i]==0)
                {
                    b[bn++]=a[i];
                    n=n/a[i];
                   i--;
                }
            }
        for(i=0; i<bn-1; i++)
            cout<<b[i]<<'*';
        cout<<b[bn-1]<<endl;


    }
    return 0;
}

原创粉丝点击