uva583 Prime Factors(很水很水。。只是纪念一下脑搭的一早晨)

B - Prime Factors
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF


  Prime Factors 

Webster defines  prime as:


prime (prim) n.[ME, fr. MF, fem. of prin first, Lprimus; akin to Lprior1 :first in time: original 2 a : having no factor except itself and one $\langle$3 is a   number $\rangle$b : having no common factor except one $\langle$ 12 and 25 are relatively  $\rangle$3 a : first in rank, authority or significance : principal b : having the highest quality or value $\langle$  television time $\rangle$ [from Webster's New Collegiate Dictionary]


The most relevant definition for this problem is 2a: An integer g>1 is said to be prime if and only if its only positive divisors are itself and one (otherwise it is said to be composite). For example, the number 21 is composite; the number 23 is prime. Note that the decompositon of a positive number g into its prime factors, i.e., 

\begin{displaymath}g = f_1 \times f_2 \times \dots \times f_n\end{displaymath}

is unique if we assert that fi > 1 for all i and $f_i \le f_j$ for i<j.

One interesting class of prime numbers are the so-called Mersenne primes which are of the form 2p- 1. Euler proved that 231 - 1 is prime in 1772 -- all without the aid of a computer.

Input 

The input will consist of a sequence of numbers. Each line of input will contain one number  g in the range -2  31 <  g <2  31, but different of -1 and 1. The end of input will be indicated by an input line having a value of zero.

Output 

For each line of input, your program should print a line of output consisting of the input number and its prime factors. For an input number  $g>0, g = f_1 \times f_2 \times\dots \times f_n$, where each  f i is a prime number greater than unity (with  $f_i \le f_j$ for  ij), the format of the output line should be


\begin{displaymath}g \mbox{\tt\ = } f_1 \mbox{\tt\ x } f_2 \mbox{\tt\ x } \dots \mbox{\tt\ x } f_n\end{displaymath}

When g < 0, if $ \mid g \mid = f_1 \times f_2 \times \dots \times f_n$, the format of the output line should be 

\begin{displaymath}g \mbox{\tt\ = -1 x } f_1 \mbox{\tt\ x } f_2 \mbox{\tt\ x } \dots\mbox{\tt\ x } f_n\end{displaymath}

Sample Input 

-190
-191
-192
-193
-194
195
196
197
198
199
200
0

Sample Output 

-190 = -1 x 2 x 5 x 19
-191 = -1 x 191
-192 = -1 x 2 x 2 x 2 x 2 x 2 x 2 x 3
-193 = -1 x 193
-194 = -1 x 2 x 97
195 = 3 x 5 x 13
196 = 2 x 2 x 7 x 7
197 = 197
198 = 2 x 3 x 3 x 11
199 = 199
200 = 2 x 2 x 2 x 5 x 5



Miguel Revilla
2000-05-19


题意:将正数表成  \begin{displaymath}g \mbox{\tt\ = } f_1 \mbox{\tt\ x } f_2 \mbox{\tt\ x } \dots \mbox{\tt\ x } f_n\end{displaymath}    这种递增素数相乘的形式

            同理 ,将负数表成   \begin{displaymath}g \mbox{\tt\ = -1 x } f_1 \mbox{\tt\ x } f_2 \mbox{\tt\ x } \dots\mbox{\tt\ x } f_n\end{displaymath}   这种递增素数相乘的形式

    不考虑输入为 1 或者 -1 的情况。


#include 
   
   
    
    
#include 
    
    
     
     

int pri[47000],vis[47000],num=0;

void getPrime(int n)
{	
	for(int i=2;i
     
     
      
      n)
			{
				break;
			}
			vis[i*pri[j]]=1;
			if(i%pri[j]==0)
			{
				break;
			}
		}
	}

}

int main()
{
	long long n;
	getPrime(46340);// 46340是比sqrt(2^31)大一点的一个数。。
	while(scanf("%lld",&n)!=EOF && n) //%lld和%I64d的问题。。调试的时候要用%I64d,提交的时候一定要改成%lld
	{
		printf("%lld =",n);
		int flag=1;
		if(n<0)
		{
			printf(" %d",-1);
			n=n*-1;
			flag=0;
		}
		for(int i=0;i
      
      
     
     
    
    
   
   


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值