设为首页 加入收藏

TOP

POJ 1365 Prime Land
2015-07-20 18:00:37 来源: 作者: 【 】 浏览:1
Tags: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.2cto.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; }
      
     
    
   
  




】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU1715大数相加 下一篇POJ 2263 Heavy Cargo(二分+并查..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: