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. 洛谷 4035 [JSOI2008]球形空间产生器

    题目戳这里 一句话题意 给你 n+1 个 n 维点,需要你求出这个n维球的球心.(n<=10) Solution 这个题目N维的话确实不好想,反正三维就已经把我搞懵了,所以只好拿二维类比. 首先 ...

  2. spring 注解管理

    一.注解准备 1.xml引入新的约束,并开启注解扫描 context:component-scan标签开启注解扫描 2.导入注解有关jar包 二.注解创建对象 1.User类 @Component( ...

  3. android 多语言(在APP里面内切换语言)

    创建SharedPreferences的管理类 public class PreferenceUtil { private static SharedPreferences mSharedPrefer ...

  4. GCC 常用选项详解

    参考gcc man page 参考:http://www.cppblog.com/seman/archive/2005/11/30/1440.html gcc and g++分别是gnu的c & ...

  5. spark0.9.0安装

    利用周末的时间安装学习了下最近很火的Spark0.9.0(江湖传言,要革hadoop命,O(∩_∩)O),并体验了该框架下的机器学习包MLlib(spark解决的一个重点就是高效的运行迭代算法),下面 ...

  6. Linux基础系列:常用命令(7)_正则表达式

    一.环境边量 每个用户登录shell需要执行的四个文件 /etc/profile /home/egon/.bashrc_profile /home/egon/.bashrc /etc/bashrc 非 ...

  7. 模仿jquery框架源码---网络

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Page& ...

  8. 最新版本express 4.2.0的快速建站--简单举例

    express是Node.js的官方唯一推荐的框架,它扩展了http工具以及一些好用的功能.如此好用的东西,赶紧的安装起来: npm install express -g 新版本的express的命令 ...

  9. [原创]java WEB学习笔记18:java EE 中的MVC 设计模式(理论)

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  10. poj 3083 Children of the Candy Corn 【条件约束dfs搜索 + bfs搜索】【复习搜索题目一定要看这道题目】

    题目地址:http://poj.org/problem?id=3083 Sample Input 2 8 8 ######## #......# #.####.# #.####.# #.####.# ...