POJ1365: Decomposition of mass factor

Source: Internet
Author: User
Tags mul

Prime Land
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3590 Accepted: 1623

Description

Everybody in the prime land is using a prime base number system. In this system, each positive an integer x is represented as Follows:let {pi}i=0,1,2,... denote the increasing sequence of a ll prime numbers. We know that x > 1 can is represented in the one-in-one-out-of-the-form for the product of powers of prime factors. This implies, there are an integer kx and uniquely determined integers ekx, ekx-1, ..., E1, E0, (Ekx > 0), that the Sequence

(Ekx, Ekx-1, ..., E1, E0)



is considered to being the representation of x in prime base number system.

It is really true if all numerical calculations in the prime base number system can seem to us a little bit unusual, or even Hard. In fact, the children on Prime land learn to add to subtract numbers several years. On the other hand, multiplication and division are very simple.

Recently, somebody had returned from a holiday in the computer land where small smart things called computers had been us Ed. It has turned out that they could is used to make addition and subtraction in prime base number system much easier. It has been decided to make an experiment and let a computer to do the operation ' minus one '.

Help people in the Prime land and write a corresponding program.

For practical reasons we'll write here the prime base representation as a sequence of such pi and ei from the prime base Representation above for which ei > 0. We'll keep decreasing order with regard to PI.

Input

The input consists of lines (at least one) each of the which except the last contains prime base representation of just one PO Sitive integer greater than 2 and less or equal 32767. All numbers in the line is separated by one space. The last line contains number 0.

Output

The output contains one line for each and the last line of the input. If X is a positive an integer contained in a line of the input, the line in the output would contain x-1 in prime base repre Sentation. All numbers in the line is separated by one space. There is no line in the "output corresponding to the last" "Null" line of the input.

Sample Input

17 15 1 2 1509 1 59 10

Sample Output

2 43 213 1 11 1 7 1 5 1 3 1 2 1

For example, test instructions: Example 2: The mass factor decomposition is performed, and the result is 3^2.
Ideas: Filter The number of dozen tables, from small to large decomposition.
#include <iostream>#include<cstring>using namespacestd;Const intmaxn=33000;BOOLISPRIME[MAXN];intPrime[maxn],top;voidsieve () {memset (IsPrime,true,sizeof(IsPrime)); isprime[0]=false; isprime[1]=false;  for(intI=2; i<maxn;i++)    {        if(Isprime[i]) {prime[top++]=i;  for(intj=i+i;j<maxn;j+=i) {isprime[j]=false; }        }    }}intMultiplyintXintN) {    intMul=1;  for(intI=1; i<=n;i++) {Mul*=x; }    returnMul;}intMETHODS[MAXN];voidSolveintx) {memset (Methods,0,sizeof(methods)); intL=0;  while(x!=1)    {        if(x%prime[l]==0) {Methods[prime[l]]++; X/=Prime[l]; }        Elsel++; }}intMain () {intX,n;    Sieve ();  while(cin>>x&&x!=0)    {        intsum=1; CIN>>N; Sum*=multiply (x,n);  while(CIN.)Get()!='\ n') {cin>>x>>N; Sum*=multiply (x,n); } Sum--;        Solve (sum);  for(inti=top;i>=0; i--)        {            if(methods[prime[i]]!=0) {cout<<prime[i]<<" "<<methods[prime[i]]<<" "; }} cout<<Endl; }    return 0;}

POJ1365: Decomposition of mass factor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.