Poj1365_prime land [prime factor decomposition] [prime number] [water question]

Source: Internet
Author: User
Prime landtime limit: 1000 ms memory limit: 10000 ktotal submissions: 3086 accepted: 1416 description


Everybody in the prime land is using a prime base number system. in this system, each positive integer x is represented as follows: Let {PI} I = 0, 1, 2 ,... denote the increasing sequence of all prime numbers. we know that x> 1 can be represented in only one way in the form of product of powers of prime factors. this implies that there is 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 be the representation of X in prime base number system.


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


Recently, somebody has returned from a holiday in the computer land where small smart things called computers have been used. it has turned out that they cocould be 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 ''.


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


For practical reasons we will 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 will keep decreasing order with regard to pi.
Input


The input consists of lines (at least one) each of which should t the last contains prime base representation of just one positive integer greater than 2 and less or equal 32767. all numbers in the line are separated by one space. the last line contains number 0.
Output


The output contains one line for each but the last line of the input. if X is a positive integer contained in a line of the input, the line in the output will contain in X-1 in prime base representation. all numbers in the line are separated by one space. there is no line in the output corresponding to the last ''null'' line of the input.
Sample Input


17 1
5 1 2 1
509 1 59 1
0
Sample output


2 4
3 2
13 1 11 1 7 1 5 1 3 1 2 1
Source


Central Europe 1997

Tell you a number of prime factor X of all the base number Pi and power EI, output X-1 of all the base number and power

Idea: This question is not difficult, but it is not easy to understand the meaning of the question. For me, the hacker did not understand it for an hour.

For example

Example 509 1 59 1

X = 509 ^ 1*59 ^ 1 = 30031

X-1 = 30030

Then answer 13 1 11 1 7 1 5 1 3 1 2 1 is X-1 = 13 ^ 1*11 ^ 1*7 ^ 1*5 ^ 1*3 ^ 1*2 ^ 1 = 30031

Then you can solve the problem by pressing the question directly .....

# Include <stdio. h> # include <string. h> # include <math. h>/* POW function description prototype: extern float POW (float X, float y); usage: # include <math. h> function: Calculate the Power Y of X. NOTE: If X is greater than zero, the result of the power index is returned. */Double P [110], E [110]; int prime [35000], E [35000]; void isprime () {Prime [0] = prime [1] = 0; For (INT I = 2; I <= 35000; I ++) {Prime [I] = 1 ;} for (INT I = 2; I <= 35000; I ++) {for (Int J = I + I; j <= 35000; j + = I) {Prime [J] = 0 ;}}int main () {int count, sign; isprime (); // For (INT I = 2; I <= 35000; I ++) // If (prime [I]) // printf ("% d", I); While (1) {COUNT = 0, Sign = 0; memset (p, 0, sizeof (p); memset (E, 0, Sizeof (e); memset (E, 0, sizeof (e); While (1) {scanf ("% lf", & P [count]); if (P [count] = 0) {Sign = 1; break;} scanf ("% lf", & E [count]); count ++; char c = getchar (); If (C = '\ n') break;} If (Sign = 1) break; double num = 1; for (INT I = 0; I <count; I ++) num * = POW (P [I], E [I]); int sum = (INT) num-1; // printf ("% d \ n", sum); int flag = 0, Pos = 2; for (INT I = 2; I <= 32767; I ++) {If (sum = 1) break; If (P Rime [I]) {While (sum % I = 0) {e [I] ++; sum/= I; If (flag = 0) {flag = 1; pos = I ;}}}for (INT I = 32767; I >=2; I --) {If (E [I]! = 0 & I! = POS) printf ("% d", I, e [I]); else if (E [I]! = 0 & I = POS) {printf ("% d \ n", I, e [I]); break ;}} return 0 ;}



Poj1365_prime land [prime factor decomposition] [prime number] [water question]

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.