博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ Prime Land
阅读量:6326 次
发布时间:2019-06-22

本文共 2825 字,大约阅读时间需要 9 分钟。

Prime Land
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 2074   Accepted: 957

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 e
kx, e
kx-1, ..., e
1, e
0, (e
kx > 0), that
The sequence
(e
kx, e
kx-1, ... ,e
1, e
0)
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 could 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 one''.
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 15 1 2 1509 1 59 10

Sample Output

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

Source

 
View Code
1 #include
2 void work(int num){ 3 int base[20]={
0},f[20]={
0},count = 0; 4 for(int i=2;i
1) { f[count] = num ; base[count++] = 1 ;}15 for(int i=count-1;i;i--)16 printf("%d %d ",f[i],base[i]) ;17 printf("%d %d\n",f[0],base[0]) ;18 }19 int main(){20 int x ,base;21 int num = 1;22 while(scanf("%d",&x) && x){23 if(x == 0)24 break;25 scanf("%d",&base) ;26 for(int i=0;i

 

转载于:https://www.cnblogs.com/jun930123/archive/2012/08/16/2641028.html

你可能感兴趣的文章
万豪酒店数据库遭入侵 5亿顾客信息或泄露
查看>>
JAVA中循环删除list中元素的方法总结
查看>>
redis 安装
查看>>
C# tips ---值类型的装箱和拆箱
查看>>
SQL some any all
查看>>
电子书下载:Programming Windows Identity Foundation
查看>>
有理想的程序员必须知道的15件事
查看>>
用于测试的字符串
查看>>
VisualSvn Server介绍
查看>>
财付通和支付宝资料收集
查看>>
PHPCMS V9数据库表结构分析
查看>>
『原创』+『参考』基于PPC的图像对比程序——使用直方图度量
查看>>
理解 IEnumerable 与 IEnumerator
查看>>
NHibernate 2.0 Beta 1 Released和一些工具
查看>>
【每天一个Linux命令】12. Linux中which命令的用法
查看>>
软件接口数据一致性机制
查看>>
微服务架构介绍和RPC框架对比
查看>>
Debian下使用OpenLDAP 管理端
查看>>
build with runtime package
查看>>
步步为营 .NET 代码重构学习笔记 九
查看>>