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

给一个数n<32768的分解质因数的形式,把n-1分解质因数

n这么小直接暴力

我也不是很懂这题意义何在,可能是考察输入吧

 #include<cstdio>
#include<iostream>
#include<cstring>
#define LL long long
#define int long long
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} bool mk[];
int pp[],len;
int p[],q[],len2;
int n,s,t;
inline void getp()
{
for (int i=;i<=;i++)
{
if (!mk[i])
{
pp[++len]=i;
for (int j=*i;j<=;j+=i)mk[j]=;
}
}
}
inline int quickpow(int a,int b)
{
int ans=;
while (b)
{
if (b&)ans=ans*a;
a=a*a;
b>>=;
}
return ans;
}
main()
{
getp();
while (~scanf("%lld",&s))
{
if (s==)break;
scanf(" %lld",&t);
n=quickpow(s,t);
char c=getchar();
while (c!='\n'&&c!=EOF)
{
scanf("%lld %lld",&s,&t);
n*=quickpow(s,t);
c=getchar();
}
n--;len2=;
for (int i=;i<=len;i++)
{
if ((LL)pp[i]*pp[i]>n)break;
if (n%pp[i]==)
{
p[++len2]=pp[i];q[len2]=;
while (n%pp[i]==)n/=pp[i],q[len2]++;
}
}
if (n!=||!len2)p[++len2]=n,q[len2]=;
for (int i=len2;i>=;i--)
{
printf("%lld %lld",p[i],q[i]);
if (i==)puts("");else printf(" ");
}
if (c==EOF)break;
}
}

poj 1365

[暑假集训--数论]poj1365 Prime Land的更多相关文章

  1. 数学--数论--POJ1365——Prime Land

    Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...

  2. [暑假集训--数论]poj1595 Prime Cuts

    A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...

  3. [暑假集训--数论]poj3518 Prime Gap

    The sequence of n − 1 consecutive composite numbers (positive integers that are not prime and not eq ...

  4. [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

  5. POJ1365 - Prime Land(质因数分解)

    题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...

  6. POJ1365 Prime Land【质因数分解】【素数】【水题】

    题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特 ...

  7. [暑假集训--数论]poj2262 Goldbach's Conjecture

    In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...

  8. [暑假集训--数论]poj2909 Goldbach's Conjecture

    For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 ...

  9. [暑假集训--数论]poj2773 Happy 2006

    Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD ...

随机推荐

  1. 关于小程序 scroll-view中设置scroll-top无效 和小说图书阅读进度条小案例

    在最近的项目有做到关于小说阅读的进度条功能,其中用到scroll-view和slider组件,发现scroll-view中的scroll-top在设置值后无效,出现这种情况大概是以下几种问题: 1.s ...

  2. React Native 初探

    推荐文章 React Native 简介:用 JavaScript 搭建 iOS 应用 (1) React Native 简介:用 JavaScript 搭建 iOS 应用 (2) React Nat ...

  3. 微信小程序的开发——01小程序的执行流程是怎样的?

    作者:叶小钗 转载至:https://www.cnblogs.com/yexiaochai/p/9346043.html 我们这边最近一直在做基础服务,这一切都是为了完善技术体系,这里对于前端来说便是 ...

  4. GNU C中__attribute__

    __attribute__基本介绍: 1. __attribute__ 可以设置函数属性.变量属性和类型属性. 2. __attribute__ 语法格式为:__attribute__ ((attri ...

  5. C盘扩容 更改C盘大小

    最近对xamarin有点兴趣,虽然网上的评论嘘声一片, 对于只想试一试的心态来说,对于网上所说的什么开发后的程序卡顿,可以用的三方库很少等, 我只想说,你们说的我不信,我要试一试看 我本来已经安装了v ...

  6. h5获取摄像头拍照功能

    完整代码展示 <!DOCTYPE html> <head> <title>HTML5 GetUserMedia Demo</title> <met ...

  7. linux下的source命令

    Linux Source命令及脚本的执行方式解析   当我修改了/etc/profile文件,我想让它立刻生效,而不用重新登录:这时就想到用source命令,如:source /etc/profile ...

  8. Insertion Sort Gym - 101955C 思路+推公式

    题目:题目链接 题意:对长为n的1到n的数列的前k个数排序后数列的最长上升子序列长度不小于n-1的数列的种数,训练赛时怎么都读不明白这个题意,最后还是赛后问了旁队才算看懂,英语水平急需拯救55555 ...

  9. 栈经典列题:Rails

    解题心得: 1.这题是先进后出的顺序,所以使用栈(先进后出表). 2.搞清楚题意,需要达成的序列和进入的序.不要弄混了. 3.思维混乱的时候要冷静,冷静,冷静~~~~! 题目: Description ...

  10. 初识Java之入门学习(扫盲)

    一,开发环境的配置 1. jdk1.8的安装 2. 环境变量的配置 3.MyEclipse8.5的安装 jdk是什么: JDK 是Java开发工具包 (Java Development Kit ) 的 ...