POJ1365——Prime Land

POJ-priority queue练习题:比较质因数个数 题目描述: 阅读详情
Prime Land
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3085 Accepted: 1415

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

Source

Central Europe 1997


题意有点读不懂啊

简单的分解质因数的题

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int p[10010];
int e[10010];
int tot;

void factor(long long n)                                         
{
	long long temp =(int)sqrt((double)n + 1.0);
	for(int i = 2; i <= n; i ++)
	{
		if(n % i == 0)
		{
			p[ ++tot] = i;
			e[tot] = 0;
			while( n % i == 0)
			{
				e[tot] ++;
				n /= i;
			}
		}
	}
	if(n != 1)
	{
		p[++ tot] = n;
		e[tot] = 1;
	}
}

int quick(int a, int b)
{
	int num = 1;
	while(b)
	{
		if(b & 1)
			num *= a;
		b >>= 1;
		a *= a;
	}
	return num;
}

int main()
{
	int a, b;
	while(~scanf("%d",&a))
	{
		if(!a)
			break;
		scanf("%d", &b);
		int num = quick(a, b);
		char ch;
		while(1)
		{
			if(getchar() == '\n')
				break;
			scanf("%d", &a);
			scanf("%d", &b);
			num *= quick(a, b);
		}
		tot = 0;
		factor(num - 1);
		for(int i = tot; i >= 1; i --)
		{
			if( i == tot)
				printf("%d %d", p[i], e[i]);
			else
				printf(" %d %d", p[i], e[i]);
		}
		printf("\n");
	}
	return 0;
}



“傻瓜”stata入门——熟悉操作界面 小白开始学习stata和matlab,零基础上手 阅读详情

相关推荐

OpenCV学习笔记(25)基于MFC和OpenCV的摄像机定标与立体匹配测试程序(20140505更新)

最近整理了一下这两年一直在用的摄像机定标与立体匹配测试程序,将代码进行了重构,界面也做了调整,分享出来方便有需要的朋友使用。当然我的编程能力有限,程序可能还有各种bug,请大家多多包涵。相关问题欢迎留言或email联系讨论,谢谢! ==================================================================================源码

晨宇思远 5万+

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

POJ1365_Prime Land【质因数分解】【素数】【水题】

程序员充电站(itcharge) 2603

ArcGIS+PLUS+InVEST三件套实战:从零搞定土地利用变化与碳储量预测(附完整数据包)

本文详细介绍了如何整合ArcGIS、PLUS模型和InVEST模型,构建土地利用变化与碳储量预测的完整研究流水线。通过多情景模拟和生态系统服务评估,提供从数据准备到结果验证的实战指南,助力研究者高效完成生态评估项目。

weixin_30399821的博客 543

POJ-1365-Prime Land 解题报告

分解质因数水题。题意:给出n按照唯一分解定理分解出的质因数和幂,请输出n-1分解后的质因数和幂,注意顺序。        我的解题思路:只是输入不太方便而已,需要用字符串输入,一次输入一行,输入完以后就处理数据就行了。        我的解题代码: #include #include #include #include #include #include usi

JZQT_T的博客 892

椭圆曲线点加的推导公式(一)

椭圆曲线点加推导过程

qq_32100199的博客 1517

lumerical-环形谐振器

利用mode求解器优化得到所需的环的总长度,即环形器的半径,然后通过varFDTD得到光场分布和透过率.

m0_61776728的博客 2189

POJ 1365 Prime Land

觉得这题最难的就是理解题意了

Good morning,good afternoon and good night 1494

全桥LLC谐振变换器变频控制工作原理与仿真

全桥LLC谐振变换器以其效率高、全范围软开关、器件电应力小等优点,越来越多地应用于大功率场合。电力电子技术的发展日益追求高频化,所带来的问题是半导体开关器件高频运行时的开关损耗急剧增加。各种软开关电路随之出现。可以有效减小开关损耗,使进一步提高开关频率成为可能。谐振式开关因其可在电流自然过零点开通半导体器件,实现零电压开关,特别适合采用MOSFET作开关的装置。最简单的谐振电路有串联谐振(SRC)和并联谐振(PRC)。SRC只能工作于降压状态,应用受限;

晞子的技术札记 3075

poj1365 Prime Land

数字的质因子分解。。 Code: #include #include #include #include using namespace std; typedef long long LL; int main() { LL n, p, t, i; int pri[100], e[100]; while (true) { cin >> p

天亮说晚安 2017

计算电磁学(三)有限差分方法

有限差分方法(FDM)是一种数值处理方法,通过将偏微分方程变换为一组代数方程,通过求解代数方程组来得到原边值问题的近似值。由于有限差分法非常简单,所以也特别的稳定高效。其中时域有限差分方法(FDTD)是电磁分析中的常用方法。在计算电磁学中,常用有限差分方法(finite difference equations)来替代微分方程。一个有限差分法通常包括三个步骤将求解域划分网格用有限差分方程逼近给定的微分方程求解在给定边界条件和初始状态下的方程常用的网格模型方阵斜方阵三角阵圆形阵。

CCC_B的博客 1640

用MATLAB计算卡方值

然后,我们计算了期望频数,即在两个分类变量独立的情况下,每个单元格的预期频数。接下来,我们使用卡方检验的公式计算了卡方值。卡方检验是一种常用的统计方法,用于确定两个分类变量之间是否存在相关性。它基于观察到的频数和期望频数之间的差异来评估分类变量之间的独立性。在MATLAB中,我们可以使用。请注意,这只是一个简单的示例代码,用于说明如何使用MATLAB计算卡方值。在实际应用中,您可能需要根据您的具体数据和研究问题进行相应的修改和调整。在上面的代码中,我们首先创建了两个分类变量。函数显示了计算得到的卡方值。

CodeNexus的博客 2658

POJ 1365 Prime Land 素数

Prime Land Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %lld & %llu SubmitStatusDescription Everybody in the Prime Land is using a prime base number system. In this system, e

Katapeltes 589

Transformer实战(40)——Transformer时间序列数据建模

Transformer 因其在自然语言处理 (Natural Language Processing, NLP) 任务中的优异表现而被广泛应用,其主要优势在于能够有效建模时间序列数据。这些数据可以是文本,也可以是非文本。本节将介绍如何使用 Transformer 进行时间序列数据建模和预测,将学习时间序列的基本概念,并在此基础上使用一个简单的模型,用以初步了解时间序列数据,并为各种预测任务奠定基础。

盼小辉丶的博客 2373

poj 1365 Prime Land (质因子分解)

题目链接:http://poj.org/problem?id=1365 题目意思:n= p1^e1* p2^ e2* ……pk^ek 现在给出p1,e1 ,p2,e2……pk,ek。求n-1 的质因子与相对应的幂,质因子从大到小 代码如下: /* * File: main.cpp * Author: ssslpk *32ms * Created on Au

三思 856

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

POJ-1365 Prime Land

题意:已知任意一个大于1的数可以表示成一些素数的乘积,即x=p1^e1*p2^e2……pn^en (pi 为素数,ei 为对应素数的个数),现给你x的表示,要你求x-1的表示。例:输入:5 1 2 1 则x=5^1*2^1=10,所以x-1=9,9可以表示成:9=3^2 输出:3 2 思路:打出素数表、然后从小到大除即可。 题目链接:http://poj.org/problem...

bancaidun1539的博客 139

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 1365 Prime Land 【素数分解】

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 a

咸鱼の小窝 777

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

(数学)POJ - 1365 Prime Land

原题链接:http://poj.org/problem?id=1365 题意: 定义:任何一个大于1的自然数N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积N=P1a1P2a2P3a3......Pnan,这里P1<P2<P3......<Pn均为质数,其中指数ai是正整数。这样的分解称为N的标准分解式 告诉你n分解后的结果,底数p...

dijieluan7764的博客 164

[水+整数分解] poj 1365 Prime Land

题意: 给2*n个数,输入的这些数构成 sum=(a[1]^b[1])*(a[2]^b[2])... 其实就是整数分解完的数。 然后让你输出分解sum-1的结果。 从大到小。 思路: 就是输入麻烦点。 注意题目说了1的时候要输出空行。 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath"

Enmity_Dark 784

poj 1365 Prime Land 质因数分解

刚开始没看懂题意。。。 输入p1 e1 p2 e2 .... 输出的是 p1^e1 + p2^e2 + ... + pn^en - 1 拆成素数乘积后每个素数的值及指数的值。按素数由大到小输出 暴力枚举就可以。。。 输入那里的字符串处理是学习的别人的。感觉很简洁就用上了 #include #include #include #include #include

Vontroy 393

poj 1365 Prime Land

题意:输入:a1,b1,a2,b2....。求出x=a1^b1 * a2^b2 * ....。将x-1这个数分解成素数的乘积。并将这些素数按从大到小的顺序输出及其幂。 思路:求出所有的素数。求出x,再因式分解。本题比较难的部分是处理输入。参考C++ primer。 #include #include #include #include #include #include using

c的专栏 608

[POJ 1365] Prime Land

Prime Land Time Limit:1000MS Memory Limit:10000K Total Submissions:3211 Accepted:1473 Description Everybody in the Prime Land is using a prime base number syst...

weixin_30834783的博客 109
上一篇: POJ1142——Smith Numbers
下一篇: hdu5014——Number Sequence
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值