POJ 1365 (Factorization rating + Prime number dozen table)

Source: Internet
Author: User



Prime Land Time limit:1000ms Memory limit:10000kb

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 is an integer kx and uniquely determined integers Ekx Ekx-1,..., E1E0, (Ekx > 0), that the sequence

(Ekx Ekx-1,..., E1E0)



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.
Inputthe input consists of lines (at least one) each of which except the last contains prime base representation of just O Ne positive 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.OutputThe, 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

The main problem (quality factor decomposition + Prime number dozen table): Give the decomposition of the mass factor of N, to find the n-1 of the mass factor decomposition formula. For example, the second group of sample, is 5^1*2^1=10, 10-1 is 9 of the quality factor decomposition, from large to small output.


Code:

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include < cstring>using namespace Std;const int maxn = 100002;bool isprime[maxn];int total,prime[maxn];int path[maxn];//Bottom int PO    [maxn];//Index int cnt;//How many factorization void Dabiao () {//Euler filter method to produce Prime number table total=0;    memset (isprime,true,sizeof (IsPrime));        for (int i=2;i<=maxn;i++) {if (Isprime[i]) {prime[total++]=i;            } for (int j=0;j<=total;j++) {if (I*PRIME[J]&GT;MAXN) break;            Isprime[i*prime[j]]=false;        if (i%prime[j] = = 0) break;    }}}void solve (int n) {//N for mass factorization cnt=0;        for (int i=0;prime[i]<=n&&n!=1;i++) {int ct=0;            while (n%prime[i]==0) {ct++;        N/=prime[i];            } if (ct!=0) {path[cnt] = Prime[i];        po[cnt++] = ct;        }} for (int i=cnt-1;i>=0;i--) {//Output decomposed if (i!=0) printf ("%d%d", path[i],po[i]); else printf ("%d%d\n", Path[i],Po[i]);    }}int Main () {Dabiao ();    int a,b,num;    Char ch;        while (~SCANF ("%d", &a) &&a) {//Note the processing of this format input scanf ("%d%c", &b,&ch);        Num=1;        num*= (int) pow (a*1.0,b*1.0);            while (ch!= ' \ n ') {scanf ("%d%d%c", &a,&b,&ch);    Num*=pow (a+0.0,b);//Here must be written in this form, do not know why, seeking answers} solve (num-1); } return 0;}



POJ 1365 (Factorization rating + Prime number dozen table)

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.