Prime Land
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3590   Accepted: 1623

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 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 举例理解题意:例2:将 进行质因数分解,结果为3^2。
思路:筛选素数打表,由小到大分解。
#include <iostream>
#include <cstring>
using namespace std;
const int MAXN=;
bool isPrime[MAXN];
int prime[MAXN],top;
void sieve()
{
memset(isPrime,true,sizeof(isPrime));
isPrime[]=false;
isPrime[]=false;
for(int i=;i<MAXN;i++)
{
if(isPrime[i])
{
prime[top++]=i;
for(int j=i+i;j<MAXN;j+=i)
{
isPrime[j]=false;
}
}
}
}
int multiply(int x,int n)
{
int mul=;
for(int i=;i<=n;i++)
{
mul*=x;
}
return mul;
}
int methods[MAXN];
void solve(int x)
{
memset(methods,,sizeof(methods));
int l=;
while(x!=)
{
if(x%prime[l]==)
{
methods[prime[l]]++;
x/=prime[l];
}
else l++;
}
}
int main()
{
int x,n;
sieve();
while(cin>>x&&x!=)
{
int sum=;
cin>>n;
sum*=multiply(x,n);
while(cin.get()!='\n')
{
cin>>x>>n;
sum*=multiply(x,n);
}
sum--;
solve(sum);
for(int i=top;i>=;i--)
{
if(methods[prime[i]]!=)
{
cout<<prime[i]<<" "<<methods[prime[i]]<<" ";
}
}
cout<<endl;
}
return ;
}

POJ1365:质因数分解的更多相关文章

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

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

  2. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  3. AC日记——质因数分解 1.5 43

    43:质因数分解 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...

  4. 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛

    4514: [Sdoi2016]数字配对 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 726  Solved: 309[Submit][Status ...

  5. 整数分解 && 质因数分解

    输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...

  6. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  7. 数学概念——J - 数论,质因数分解

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  8. hdu1405 第六周J题(质因数分解)

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Desc ...

  9. POj3421 X-factor Chains(质因数分解+排列组合)

    POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...

随机推荐

  1. [转载] 把Nutch爬虫部署到Hadoop集群上

    http://f.dataguru.cn/thread-240156-1-1.html 软件版本:Nutch 1.7, Hadoop 1.2.1, CentOS 6.5, JDK 1.7 前面的3篇文 ...

  2. Unicode Category

    Lu(letter,uppercase):大写字母. Ll(letter.lowercase):小写字母. Lt(letter,titlecase):词首字母大写的字母. Lm(letter,modi ...

  3. [闲来无事,从头再来][C51篇]导读

    目       的:  通过学习C51,熟悉单片机,熟悉C语言,熟悉单片机系统的外部电路. 方       法:  通过看书和使用板子做实验来进行学习 参考资料: <新概念51单片机C语言教程& ...

  4. 【ELK】抓取AWS-ELB日志的logstash配置文件

    前言 ELK搭建没有难度,难的是logstash的配置文件,logstash主要分为三个部分,input,filter和output. input,输入源可选的输入源由很多,详情见ELK官网,这里我们 ...

  5. DEV开发之汉化

    public class Chinese { public Chinese() { Localizer.Active = new XtraEditors_CN(); GridLocalizer.Act ...

  6. stm32非操作系统开发和带uCos的开发的区别,及一些解析

    从文件角度来看core_cm4.h和stm32f4xx.h分别从内核寄存器和外设寄存器来定义其地址和结构体,是用c语言访问硬件必须的文件,所以这两个文件不论是否带操作系统,都是必须包含进工程的. re ...

  7. inline-block间距解决方案

    当我们将元素设为inline-block时,总是会莫名其妙出现一些间距 <!DOCTYPE html> <html> <head> <meta charset ...

  8. mini2440移植uboot 2011.03(上)

    参考博文: <u-boot-2011.03在mini2440/micro2440上的移植> 本来我想移植最新版的uboot,但是移植却不太成功,所以先模仿他人的例子重新执行一遍,对uboo ...

  9. Spring Cloud之Eureka自我保护环境搭建

    Eureka详解 服务消费者模式 获取服务 消费者启动的时候,使用服务别名,会发送一个rest请求到服务注册中心获取对应的服务信息,让后会缓存到本地jvm客户端中,同时客户端每隔30秒从服务器上更新一 ...

  10. Java -- eclipse常用快捷键