POJ 1365 / Central Europe 1997 Prime Land (数论)

基于STM32的智能交通灯管理系统设计 本项目基于STM32微控制器设计了一个智能交通灯管理系统,通过多个传感器模块实现对交通灯的智能化控制。项目涉及硬件电路设计、传感器数据采集和逻辑控制实现,适用于城市交通路口或小区路口。该基于STM32的智能交通灯系统通过超声波传感器实现了流量监测,结合LED和蜂鸣器实现了自动交通信号控制,适用于城市或社区路口。基于STM32CubeMX生成的框架,编写红绿灯切换、流量监测和蜂鸣器控制的代码。以下为主循环,通过不断读取传感器数据,结合交通灯和蜂鸣器模块实现智能交通灯控制。 阅读详情
Prime Land

Time Limit:  1000MS
Memory Limit: 10000K

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

学英语:
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.
输入有至少一行,除了最后一行,每行都包含了一个数的素因子分解表示,该数大于2且小于或等于32767.

完整代码:
/*0ms,116KB*/

#include<cstdio>
#include<cstring>
#include<cmath>

char s[24];///刚好
int base[6], index[6];///刚好

int main(void)
{
	while (gets(s), s[0] != '0')
	{
		memset(base, 0, sizeof(base));
		memset(index, 0, sizeof(index));
		int temp = 0, count = 0;
		bool which = true;
		for (int i = 0; s[i]; ++i)
		{
			if (s[i] != ' ')
				temp = temp * 10 + s[i] - '0';
			else
			{
				if (which)
					base[count] = temp;
				else
					index[count++] = temp;
				which = (which ? false : true);
				temp = 0;
			}
		}
		///最后s[i] == '\0'退出
		index[count++] = temp;
		int ans = 1;
		for (int i = 0; i < count; ++i)
			for (int j = 0; j < index[i]; ++j)
				ans *= base[i];///整数的幂运算最好用for代替!
		--ans;
		count = 0;
		int sqrtans = (int)sqrt((double)ans);
		for (int i = 2; i <= sqrtans; ++i)
		{
			if (ans % i == 0)
			{
				index[count] = 0;
				base[count] = i;
				while (ans % i == 0)
				{
					++index[count];
					ans /= i;
				}
				count++;
			}
		}
		if (ans > 1) ///无法分解
		{
			base[count] = ans;
			index[count++] = 1;
		}
		///逆序输出
		for (int i = count - 1; i > 0; --i)
			printf("%d %d ", base[i], index[i]);
		printf("%d %d\n", base[0], index[0]);
	}
	return 0;
}

先打表的方法:

/*16ms,128KB*/

#include<cstdio>
#include<cstring>
#include<cmath>

char s[24];///刚好
int base[6], index[6], prime[43], c = 0;
bool vis[192];

inline void create_prime()
{
    for (int i = 2; i <= 191; ++i)
        if (!vis[i])
        {
            prime[c++] = i;
            for (int j = i * i; j <= 191; j += i)
                vis[j] = true;
        }
}

int main(void)
{
    create_prime();
	while (gets(s), s[0] != '0')
	{
		memset(base, 0, sizeof(base));
		memset(index, 0, sizeof(index));
		int temp = 0, count = 0;
		bool which = true;
		for (int i = 0; s[i]; ++i)
		{
			if (s[i] != ' ')
				temp = temp * 10 + s[i] - '0';
			else
			{
				if (which)
					base[count] = temp;
				else
					index[count++] = temp;
				which = (which ? false : true);
				temp = 0;
			}
		}
		///最后s[i] == '\0'退出
		index[count++] = temp;
		int ans = 1;
		for (int i = 0; i < count; ++i)
			for (int j = 0; j < index[i]; ++j)
				ans *= base[i];///整数的幂运算最好用for代替!
		--ans;
		count = 0;
		int sqrtans = (int)sqrt((double)ans);
		for (int i = 0; prime[i] <= sqrtans; ++i)
		{
			if (ans % prime[i] == 0)
			{
				index[count] = 0;
				base[count] = prime[i];
				while (ans % prime[i] == 0)
				{
					++index[count];
					ans /= prime[i];
				}
				count++;
			}
		}
		if (ans > 1) ///无法分解
		{
			base[count] = ans;
			index[count++] = 1;
		}
		///逆序输出
		for (int i = count - 1; i > 0; --i)
			printf("%d %d ", base[i], index[i]);
		printf("%d %d\n", base[0], index[0]);
	}
	return 0;
}


YOLOv8/v9 遥感图像目标检测实战指南:建筑物检测与变化监测 遥感图像在城市规划、灾害评估、农业监管等领域应用广泛,但传统目标检测方法存在效率低、精度不足、难以适配遥感图像大尺寸、多尺度目标等问题。本文以“建筑物检测与变化监测”为核心,基于DOTA、NWPU VHR-10等公开数据集,系统讲解YOLOv8/v9在遥感图像中的实战流程。从数据获取、格式转换、模型训练优化,到大图切片推理、建筑物变化监测,全程提供可复现的代码与参数配置。通过针对性优化(旋转增强、切片推理等),模型在NWPU VHR-10数据集上mAP50达0.85以上,可适配卫星影像、无人机航拍等多场景 阅读详情

相关推荐

解密高并发系统的瓶颈:五大解决方案

在互联网应用中,高并发是指在短时间内同时有大量的用户访问一个网站或服务,造成系统压力过大,导致服务器宕机或服务停止响应的情况。高并发是互联网应用面临的一个重要问题,需要采取一系列措施来解决。负载均衡、缓存、数据库优化、异步处理和分布式架构是解决高并发问题的主要方法。在实际应用中,需要根据具体情况选择不同的方法来解决高并发问题。在高并发情况下,使用负载均衡是解决问题的一种常见方法。负载均衡可以通过将请求分配到多个服务器上,从而减少单个服务器的负载。这可以通过硬件设备或软件实现。

BUG制造者:图图 <p>这是一个P标签</p> 3913

poj1365

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 increa

◆◇丶生如夏花。谁来订阅我的悲伤 505

ABP框架实战:从零搭建多租户应用(含完整代码示例)

本文详细介绍了如何使用ABP框架从零构建多租户SaaS应用,涵盖多租户架构设计、数据隔离实现、租户管理及性能优化等核心内容。通过完整的代码示例,帮助开发者快速掌握企业级数据隔离系统的开发技巧,提升SaaS应用开发效率。

weixin_29247219的博客 268

PKU 1365 Prime Land

<br />内存限制10000k,错看成了1000k,一边骂POJ不厚道一边千方百计缩略mem开支,耽误良久,RE良久。艹<br />素数筛选 + 素因子拆分<br />#include <pzjay_cpy> using pzjay:space std; const int sup =4300;//预留sup个位置,略大于oo范围内生成的实际素数个数 const int oo = 40000; bool isp[oo + 10]; int prime[sup]; int x; int ans

Belong to Sopranos 1123

微处理器实验报告-实验四

实验四 可编程定时/计数器8253实验 一、实验要求 利用8086外接8253可编程定时/计数器,可以实现方波的产生。 二、实验目的 1、学习8086与8253的连接方法。 2、学习8253的控制方法。 3、掌握8253定时器/计数器的工作方式和编程原理

青竹小轩的博客 5123

汽车售后诊断 ODX 和 OTX 对比分析报告

在汽车行业不断发展的当下,汽车售后诊断技术对于保障车辆性能、维护车主权益以及提升汽车品牌服务质量起着至关重要的作用。随着汽车电子化程度的不断提高,售后诊断所涉及的数据和流程愈发复杂,这就促使行业需要更加标准化、高效化的诊断技术方案。开放诊断数据交换(ODX)和开放测试序列交换(OTX)便是在这样的背景下应运而生的两种重要标准,它们为汽车售后诊断提供了强大的支持。本报告将深入剖析 ODX 和 OTX 的技术细节、应用场景、优势与挑战,并进行全面的对比,旨在为汽车行业从业者在选择和应用这两种标准时提供有价值的参

芊言凝语 1647

数学--数论--POJ1365——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 al...

日拱一卒,功不唐捐 2877

OpenClaw 3.13 + Mac mini M4 集成 qmd 记忆存储:qmd embed 卡死 / 报错 sqlite-vec 不可用 终极解决教程

模型加速让 qmd 从国内镜像下载模型,避免网络超时;SQLite 扩展支持:修改 qmd 源码后,Bun 不再使用内置 SQLite,而是调用 Homebrew 安装的,该版本支持接口,可正常加载vec0.dylib向量扩展;OpenClaw 3.13 适配:核心逻辑与 OpenClaw 3.13 的 qmd 记忆调用逻辑完全兼容,无需额外调整;sqlite-vec 加载:qmd 自动通过sqlite-vec包获取vec0.dylib路径,调用完成向量扩展加载,实现高效向量搜索。

wuanxionglidui的博客 1313

A - Prime Subtraction(素数)

You are given two integers x and y(it is guaranteed that x>y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y? Recall that a prim...

晚安( ̄o ̄) . z Z 557

一种独特机理驱动的化学反应分类器详解

代码位置第 47-300+ 行// atom_494: 硫原子,度数=2,化合价=2,无H,无电荷!// atom_35: 氧原子,度数=1,1个H,无电荷// atom_347: 氧原子,度数=2,无H,无电荷!→atom_494()[OD1h1+0]→atom_35()→atom_347()特性传统方法(MCS)NameRXN(机理驱动)匹配策略最大公共子结构原子类型模式 + 操作码时间复杂度O(n) - 线性扫描机理理解无内置化学机理原子映射需额外计算自动推导准确性结构相似。

ASKCOS博客 164

YOLOv11 改进 - 注意力机制 | EMA (Efficient Multi-Scale Attention) 高效多尺度注意力:跨空间学习与多分支协同增强特征表征,优化多尺度目标检测

本文介绍了高效多尺度注意力(EMA)模块及其在YOLOv11中的结合应用。现有注意力机制在通道维度缩减时可能影响深度视觉表示,EMA模块通过结合通道和空间信息、采用多尺度并行子网络结构等创新点,实现了高效的多尺度注意力机制。其基本原理包括通道和空间注意力结合、多尺度并行子网络设计等。在多个流行基准数据集上的实验表明,该模块能有效提高特征表示能力。我们将EMA集成进YOLOv11,实验证明改进后的模型在目标检测任务中性能优越,具有广泛应用前景

魔改工程师的博客 1299

pku1365 Prime Land (数论,合数分解模板)

题意:给你一个个数对a, b 表示ab这样的每个数相乘的一个数n,求n-1的质数因子并且每个指数因子k所对应的次数 h. 先把合数分解模板乖乖放上: for (int i = 2; ans != 1; ++i) { if (ans%i == 0) { num[cnt] = i; i...

weixin_33985507的博客 166

YOLOv11改进策略【Neck】| 适用关键点检测:PSFM,深层语义融合模块 引入深层与浅层交叉注意力机制,动态建模不同层级的全局语义依赖关系

本文记录的是利用PSFM 模块改进 YOLOv11 的颈部融合部分,专门用于关键点检测。PSFM模块(Profound Semantic Fusion Module,深层语义融合模块) 通过在特征提取网络的深层引入跨模态交叉注意力机制,动态建模红外与可见光特征的全局语义依赖关系。本文将其应用到的颈部部分,融合深层与浅层特征,捕捉长距离语义关联,增强融合特征的判别性与场景理解能力,为检测头提供包含全局上下文的高层语义表示,从而提升模型在复杂场景下的目标检测准确率与语义推理鲁棒性。Rethinking the

Limiiiing的博客 657

【poj 1365】 Prime Land 【Central Europe 1997】

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

TLECODE的博客 378

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

POJ1365——Prime Land(素数筛选加暴力)

题目链接      这是一道素数的水题,唯一的难点就是理解题意,大致是说给你一列数,a1,a2,a3,a4,a5,a6,.......然后按(a1^a2)*(a3^a4)*(a5^a6).......得到一个和值sum,然后把sum-1,再按(a1^a2)*(a3^a4)*(a5^a6).......的格式对sum-1分解质因式,比如样例中的5 1 2 1,就得到sum=5^1+2^1=10,然

Jason_crawford的博客 892

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ 1365 Prime Land(整数拆分)

  题意:感觉题意不太好懂,题目并不难,就是给一些p和e,p是素数,e是指数,然后把这个数求出来,设为x,然后让我们逆过程输出x-1的素数拆分形式,形式与输入保持一致。   思路:素数打表以后正常拆分即可。   注意:输入过程需要优化,我以前经常使用字符串模拟的方式,后来发现那种方法比较笨,还是下面的方法简洁;代码如下:    #include<iostream> #in...

weixin_30677617的博客 159

poj1365 整数分解(质因数分解)

题意:给出一个数x的质因数表达式,请你算出x-1的质因数表达式 分析: 首先求出x,然后对x-1进行整数分解(质因数分解),整数分解可以直接套模板。 在处理过程中,发现用int定义x和y时,用pow函数运算时会造成数据丢失,因此用double定义。 首先看质因数分解模板: //摘自《挑战程序设计竞赛》p118 map prime_factor(int n) { map

天行健,君子以自强不息 1495

A. Prime Subtraction

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given two integersxxandyy(it is guaranteed thatx>yx>y). You may...

无知的我 880

CF组赛补题-Prime Subtraction

You are given two integersxxandyy(it is guaranteed thatx>yx>y). You may choose anyprimeintegerppand subtract it any number of times fromxx. Is it possible to makexxequal toyy? Recall that aprimenumber is a positive integer that has e...

m0_54674275的博客 767

poj 1365

<br /> Prime LandTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1246 Accepted: 556<br />DescriptionEverybody 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,

neoxuhaotian的专栏 1545

POJ-1365-Prime Land

题目给出你一个数分解成几个素数相乘的形式, 例如样例2: 5 1 2 1 10=5^1*2^1 然后要求你求出根据所给展开形式得到原数num,求num-1的展开形式 思路: 我先用筛数法把素数全部找出来,然后依次找寻~ 代码: #include #include #include using namespace std; const int maxn=10000; int pri[

z309241990的专栏 1366

POJ 1365(质因数分级+素数打表)

题目大意(质因数分解+素数打表):给出n的质因数分解式,求n-1的质因数的分解式。比如第二组sample,就是5^1*2^1=10, 求10-1即9的质因数分解,从大到小输出。

Menglei Min 1027

HIT OJ 1069 哈工大

Prime Land Source : ACM ICPC Central European Regional 1997 Time limit : 1 sec Memory limit : 32 M Submitted : 238, Accepted : 133 Everybody in the Prime Land is ...

lilisalo 287

Prime Land

istringsteam

傻的让人心疼 471

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

天亮说晚安 2022
上一篇: 类型转换与字符串赋值、分割、合并、复制、比较、查询、翻转详解 (完整代码)
下一篇: POJ 1033 / Northeastern Europe 1998 Defragment (模拟&队列)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址