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. Javascript对数组的操作--转载

    在jquery中处理JSON数组的情况中遍历用到的比较多,但是用添加移除这些好像不是太多. 今天试过json[i].remove(),json.remove(i)之后都不行,看网页的DOM对象中好像J ...

  2. LOJ#10117. 「一本通 4.1 练习 2」简单题

    LOJ#10117. 「一本通 4.1 练习 2」简单题 题目描述 题目来源:$CQOI 2006$ 有一个$n$个元素的数组,每个元素初始均为$0$.有$m$条指令,要么让其中一段连续序列数字反转— ...

  3. 我的Android进阶之旅------>WindowManager.LayoutParams介绍

    本文转载于: http://hubingforever.blog.163.com/blog/static/171040579201175111031938/ 本文参照自: http://develop ...

  4. activiti 基础搭建

    首先在eclipse内添加activiti的插件,https://blog.csdn.net/qq_22701869/article/details/79537971 1.创建一个maven的java ...

  5. ABAP 内表

    定义内表 1. 先声明表结构, 再根据表结构定义内表.   TYPES: BEGIN OF w_itab, a(10), b(10), END OF w_itab. DATA: itab1 type ...

  6. Springmvc注解启用

      http://www.blogbus.com/wanping-logs/235898637.html 使用注解的原因 最方便的还是启用注解 注解方便,而且项目中很流行. 配置文件尽量减少,主要使用 ...

  7. valuestack,stackContext,ActionContext.之间的关系以及action的数据在页面中取得的方法

     转自:http://blog.csdn.net/quechao123/article/details/4406148 1.三者之间的关系如下图所示: 2.action的数据在页面中取得的方法 在st ...

  8. border --- 透明边框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. html ---- web sql 例子

    <!doctype html> <html> <head> <meta charset="utf-8"> <script> ...

  10. vim 真是上瘾啊

    再次更新 .vimrc " leaderlet mapleader = ","nnoremap <leader>ev :vsplit ~/.vimrc< ...