程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ 1365 Prime Land

POJ 1365 Prime Land

編輯:C++入門知識

POJ 1365 Prime Land


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<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc3ViPiwgZTxzdWI+MDwvc3ViPikgPGJyPgo8YnI+Cjxicj4KPGJyPgppcyBjb25zaWRlcmVkIHRvIGJlIHRoZSByZXByZXNlbnRhdGlvbiBvZiB4IGluIHByaW1lIGJhc2UgbnVtYmVyIHN5c3RlbS4gPGJyPgo8YnI+Ckl0IGlzIHJlYWxseSB0cnVlIHRoYXQgYWxsIG51bWVyaWNhbCBjYWxjdWxhdGlvbnMgaW4gcHJpbWUgYmFzZSBudW1iZXIgc3lzdGVtIGNhbiBzZWVtIHRvIHVzIGEgbGl0dGxlIGJpdCB1bnVzdWFsLCBvciBldmVuIGhhcmQuIEluIGZhY3QsIHRoZSBjaGlsZHJlbiBpbiBQcmltZSBMYW5kIGxlYXJuIHRvIGFkZCB0byBzdWJ0cmFjdCBudW1iZXJzIHNldmVyYWwgeWVhcnMuIE9uIHRoZSBvdGhlciBoYW5kLCBtdWx0aXBsaWNhdGlvbiBhbmQgZGl2aXNpb24KIGlzIHZlcnkgc2ltcGxlLiA8YnI+Cjxicj4KUmVjZW50bHksIHNvbWVib2R5IGhhcyByZXR1cm5lZCBmcm9tIGEgaG9saWRheSBpbiB0aGUgQ29tcHV0ZXIgTGFuZCB3aGVyZSBzbWFsbCBzbWFydCB0aGluZ3MgY2FsbGVkIGNvbXB1dGVycyBoYXZlIGJlZW4gdXNlZC4gSXQgaGFzIHR1cm5lZCBvdXQgdGhhdCB0aGV5IGNvdWxkIGJlIHVzZWQgdG8gbWFrZSBhZGRpdGlvbiBhbmQgc3VidHJhY3Rpb24gaW4gcHJpbWUgYmFzZSBudW1iZXIgc3lzdGVtIG11Y2ggZWFzaWVyLiBJdCBoYXMgYmVlbiBkZWNpZGVkCiB0byBtYWtlIGFuIGV4cGVyaW1lbnQgYW5kIGxldCBhIGNvbXB1dGVyIHRvIGRvIHRoZSBvcGVyYXRpb24gYGBtaW51cyBvbmU="'.

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 except 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 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




題目大意,輸入一行數,例如 a,b,c,d,e,f...... 然後問 a^b*c^d*e^f*.... 的結果減去1後由哪些素數可以乘得,輸出素數(由大到小)和個數,

對於此題我只想說 cmath 的pow(快速冪)函數對整型有誤差,且用且珍惜,最好手寫,(⊙o⊙)…


還有一點,題目說不會超 int 所以不用擔心什麼了


上代碼了,解釋在代碼中



#include
#include
#include
#include
using namespace std;

#define N 100005

int a[N],b[N];

struct stud{
int a,len;
}f[1000];

int k=0;


void inset()   //素數表
{
    int i,j;
    for(i=2;i=0;i--)
           if(i==0)
              printf("%d %d\n",f[i].a,f[i].len);
       else
              printf("%d %d ",f[i].a,f[i].len);

    }
    return 0;
}




  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved