POJ 1365 Prime Land

python 爬虫 xpath 存储到数据库 参考 阅读详情

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

Source




题目大意,输入一行数,例如  a,b,c,d,e,f......  然后问 a^b*c^d*e^f*....    的结果减去1后由哪些素数可以乘得,输出素数(由大到小)和个数,

对于此题我只想说  cmath 的pow(快速幂)函数对整型有误差,且用且珍惜,最好手写,(⊙o⊙)…


还有一点,题目说不会超  int  所以不用担心什么了


上代码了,解释在代码中



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define N 100005

int a[N],b[N];

struct stud{
int a,len;
}f[1000];

int k=0;


void inset()   //素数表
{
    int i,j;
    for(i=2;i<N;i++)
        if(a[i]==0)
    {
        b[k++]=i;
        for(j=i*2;j<N;j+=i)
            a[j]=1;
    }
}

int pow(int a,int b)  // a^b  快速幂函数
{
    int n;
    n=1;
    while (b)
    {
        if (b%2==1)
            n=n*a;
        a=a*a;
        b=b/2;
    }
    return n;
}

int main()
{
    int i,j;
    int n,m,sum;

    inset();

    while(scanf("%d",&n),n)
    {
        scanf("%d",&m);
        sum=pow(n,m);

        char c;
        while(scanf("%c",&c)&&c!='\n')  //非常巧妙的地方哟
        {
            scanf("%d%d",&n,&m);
            sum*=pow(n,m);
        }
        sum--;

       int te=0;

       for(i=0;i<k&&sum!=1;i++)
        if(sum%b[i]==0)
       {
           f[te].a=b[i];      //保存该素数
           f[te].len=0;

           while(sum%b[i]==0)
           {
               f[te].len++;   //记录该素数个数
               sum/=b[i];    
           }
           te++;
       }

       for(i=te-1;i>=0;i--)
           if(i==0)
              printf("%d %d\n",f[i].a,f[i].len);
       else
              printf("%d %d ",f[i].a,f[i].len);

    }
    return 0;
}


  



博途 V16(TIA portal V16)安装教程 本文提供了西门子TIA Portal V16软件的完整安装指南。内容包括百度网盘下载链接(提取码kv69)、详细安装步骤(关闭安全保护、典型安装设置)、授权破解方法,以及PLCSIM仿真功能的使用说明。重点演示了S7-1200 PLC程序的仿真过程,解析了仿真界面各元素功能,包括状态指示灯(RUN/STOP/ERROR)、操作按钮(RUN/STOP/MRES)和网络接口状态等。通过图文并茂的方式,完整呈现了从软件安装到PLC程序仿真的全流程操作。 阅读详情

相关推荐

MiniMax H3本地部署与ComfyUI集成实战:从环境配置到提示词优化

文本到视频生成是AI内容创作领域的关键技术,它基于扩散模型等深度学习原理,将自然语言描述转化为连贯的动态视觉序列。这项技术的核心价值在于大幅降低了视频制作的门槛,为短视频创作、概念可视化、教育内容生成等场景提供了高效工具。在实际工程实践中,成功部署和运行此类模型,如近期备受关注的MiniMax H3,需要精准处理环境配置、显存优化和提示词工程等环节。其中,解决“CUDA error: no kernel image is available”等版本兼容性问题,以及针对“8G显存”等有限资源进行参数调优,是确

weixin_33674976的博客 478

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

[pcie]gen6 下 L0p

000b~100b: 触发L0p 操作流程协商工作link width 到target link width.为111b:link width 硬件动态调整。硬件动态:Device control 3 register.target link width=111b当pcie链路检测到空闲状态时,设备可以主动进入L0p状态。L0p 是pcie gen6 新引入的链路状态,是L0的子状态。(5)LINK WIDTH:当LINK WIDTH CHANGE.cmd为Request时表示请求的链路宽度。

BIG_APPLE1的博客 1676

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

【架构设计】DDD 到底解决了什么问题

DDD作为架构设计思想帮助微服务控制规模复杂度,那它是怎么做到的呢?第一章提出了架构的根本目是解决系统复杂度,并简要说明系统复杂度的六个来源及通用解法,为我们设计架构提供了清晰可执行的操作思路。

DreamSun的博客 1161

Claude Code启动失败解决方案,执行文件不兼容一键修复

Claude Code命令行工具突然报错,显示"不支持的16位应用程序"。作者排查Node版本无果后,发现是Anthropic更新导致Windows兼容性问题。解决方法很简单:卸载旧版、切换npm镜像源、重装最新版即可恢复。经验教训:遇到类似问题应先搜索社区反馈,避免无谓排查,同时注意npm源使用后及时还原。整个踩坑过程虽折腾,但最终只是简单的重装问题。

1456

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

日拱一卒,功不唐捐 2874

win11重装系统简易教程-小白也可以上手!

本文介绍一下win11系统重装的各个步骤,也作为记录供自己后面查看。附上我之前参考的一位知乎大神写的重装win10系统文章的地址本文用到的工具全部是,不需要下载第三方镜像文件(不是说这个不好,只是第三方的软件或镜像文件网上非常多,琳琅满目,小白需要筛选甄别,直接用官方的就比较省心,大神请自便~)

Sddqa的博客 1万+

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

Pytorch学习笔记(III)——提取特征

目录一、引言二、具体步骤1、参数模型2、网络结构3、参数载入4、特征提取器5、读取图片三、完整代码 一、引言   深度学习在许多任务中主要充当着特征学习的作用,而学习完的特征才是后续应用的一个关键。本文将主要介绍,如何提取任意目标层的特征图。   本文以输入数据为图片为例。 二、具体步骤 1、参数模型 博主使用了ResNet50训练了一个人脸识别的网络   训练完成的深度学习模型,我们会保存一...

lockonlxf的博客 2643

Vue3 - 详解实现网站接入钉钉扫码登录功能,钉钉授权生成登录二维码用户用手机扫描二维码登陆,支持弹框式、浏览器单独新开页显示,钉钉扫描二维码登录详细流程及示例代码,最新vue集成钉钉扫码授权登录!

vue3,nuxt3,钉钉,扫码登录,vue3钉钉扫码登陆,钉钉授权第三方WEB网站扫码登录功能,钉钉扫码登录第三方网站,单点登录,二维码不显示,报错,扫了没反应,出错,vue3钉钉扫码登录,内嵌,获取个人信息,pc网页钉钉登录,钉钉扫码登录怎么新开一页,跳页显示二维码,内嵌登录二维码,iframe新页面弹出,弹出一个小窗口显示登录二维码,登录报错,扫码没反应,解决手机点登录报错没反应,官方文档,手机扫描钉钉二维码登录网站,页面弹出一个小窗口而不是打开一个页面,vue3中使用iframe实现另开小窗口扫码登

🏆 前端领域优质创作者 3694

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的博客 890

基于MATLAB的鲁棒主成分分析(Robust PCA)图像去噪

鲁棒主成分分析(Robust PCA)是一种有效的图像去噪方法,它能够在保持图像细节的同时去除噪声。本文将介绍如何使用MATLAB实现基于鲁棒PCA的图像去噪,并提供相应的源代码。它假设噪声是随机的、高斯分布的,并将图像分解为一个低秩矩阵和一个稀疏矩阵的和。低秩矩阵表示图像的结构和纹理信息,稀疏矩阵表示图像中的噪声和细节信息。接下来,我们将图像矩阵减去均值,得到规范化的图像矩阵。然后,我们将灰度图像转换为矩阵形式,并计算图像的均值。通过分离出低秩矩阵和稀疏矩阵,我们就得到了去噪后的图像和残差图像。

DevRevolt的博客 1125

POJ-1365-Prime Land 解题报告

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

JZQT_T的博客 892

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

POJ1365——Prime Land

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

Alex 844

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

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

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

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

[水+整数分解] 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 783

(数学)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 质因数分解

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

Vontroy 393
上一篇: poj 1861(最小生成树)
下一篇: HDU 3038 How Many Answers Are Wrong
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值