POJ - 2325 Persistent Numbers

2023-11-20

The multiplicative persistence of a number is defined by Neil Sloane (Neil J.A. Sloane in The Persistence of a Number published in Journal of Recreational Mathematics 6, 1973, pp. 97-98., 1973) as the number of steps to reach a one-digit number when repeatedly multiplying the digits. Example:
679 -> 378 -> 168 -> 48 -> 32 -> 6.

That is, the persistence of 679 is 6. The persistence of a single digit number is 0. At the time of this writing it is known that there are numbers with the persistence of 11. It is not known whether there are numbers with the persistence of 12 but it is known that if they exists then the smallest of them would have more than 3000 digits.
The problem that you are to solve here is: what is the smallest number such that the first step of computing its persistence results in the given number?
Input
For each test case there is a single line of input containing a decimal number with up to 1000 digits. A line containing -1 follows the last test case.
Output
For each test case you are to output one line containing one integer number satisfying the condition stated above or a statement saying that there is no such number in the format shown below.
Sample Input
0
1
4
7
18
49
51
768
-1
Sample Output
10
11
14
17
29
77
There is no such number.
2688

题意描述:给出一个数,让你求出另外一个数他的每一位相乘等于此数,并且是最小的
679 -> 378 -> 168 -> 48 -> 32 -> 6
前一个数的各位数字的乘积等于下一个数。
在这里插入图片描述

解题思路:

最直接的想法就是将该数按从大到小的顺序分解因子。即按9,8,7,6,5,4,3,2的顺序,每个数都试除,如果该数可除,则继续尝试到不能被该数整除为止!最后将所有因子按从小到大的顺序输出即可。

AC代码

#include<stdio.h>
#include<string.h>
int l;
char a[1100];
int b[1000020];
int kk(int n)
{
    int i,j,sum=0,t[1100];
    for(i=0;i<l;i++)//大数除法 //模拟除法运算过程 
    {
        sum=a[i]+sum*10;
        t[i]=sum/n;
         sum=sum%n;
    }
    if(sum)
        return 0;
    int k = 0;
    while(t[k]==0)
	k++;
	l=l-k;
    for(i=0;i<l;i++)
        a[i]=t[k++];
    return 1;
}
int main()
{
    while(scanf("%s",&a)!=EOF)
    {
		if(a[0]=='-'&&a[1]=='1')//输入-1结束 
            break;
         l=strlen(a);
         if(l==1)//输入为一个数字的时候 
        {
        	printf("1%s\n",a);
        	continue;
		}
        int k=0;
         for(int i=0;i<l;i++)
            a[i]-='0';
            for(int i=9;i>=2;i--)
               while(kk(i))//判断能否满足整除 
                   b[k++]=i;
            if(l!=1)//没能被除尽 
            {
            	printf("There is no such number.\n");
            	continue;
			}
            if(k==1)//因子是1和本身
            {
				b[k++]=1;
            }
			for(int i=k-1;i>=0;i--)
	                printf("%d",b[i]);
	            printf("\n");
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

POJ - 2325 Persistent Numbers 的相关文章

  • sql drop和delete区别

    drop与delete的区别 初学sql语言 难免被drop和delete用法弄混 二者都有删除的意思 那它们又有什么区别呢 drop主要用于删除结构 例如删除数据库 drop database XX 删除表 drop table XX 字
  • SyntaxError: Unexpected end of JSON input解决方法和思路

    最近在写一个前后台交互的需求 前台点击编辑按钮 直接报错 SyntaxError Unexpected end of JSON input 网上查了下基本都是 一般 双引号 单引号 未成对输入时导致报错 但是我这边没法解决 重新检查了Jav
  • 零基础玩转树莓派(三)—通过SSH远程连接树莓派

    在树莓派使用过程中 我们会经常进行一些调试工作 不方便一直将树莓派与显示屏等相连 需要通过SSH来远程连接访问控制树莓派 一 Windows电脑客户端 使用SSH远程服务 需要先在控制电脑上安装一个客户端PUTTY 1 客户端下载 网页搜索

随机推荐

  • Ubuntu 20.04 如何设置永不息屏

    右键进入settings 找到power 将Blank Screen 设置为Never
  • js时间戳转日期

    方式一 方式一 var date new Date parseInt timeStart 1000 toLocaleString replace d 1 2 最后得到的是2019 8 4 上午9 29 格式的数据 方式二 function
  • Windows10 关于系统中断CPU占用过高导致电脑变卡的解决办法

    Windows10 关于系统中断CPU占用过高导致电脑变卡的解决办法 最近一段时间笔记本一直很卡 不管打开几个程序 任务管理器中总会有CPU占用80 以上 这一度让我抓狂 开始网上搜教程 然后开始了我的各种硬件禁用的道路 这个试了好久 为了
  • 洛谷P1010 [NOIP1998 普及组] 幂次方

    文章目录 前言 题目描述 输入格式 输出格式 样例 1 样例输入 1 样例输出 1 数据范围 代码 解析 结尾 前言 在做完洛谷P1010 NOIP1998 普及组 幂次方这道题之后 我对于现在的学习有了些许认识 题目描述 任何一个正整数都
  • 如何处理低概率出现的bug???

    原文链接 一般的低概率bug 不足以导致系统崩溃的bug 方案1 仔细检查是否是自己的执行步骤 或者误操作导致的bug 提交给相关人员 方案2 通过日志相关信息处理 提交相关开发人员 方案3 通过截图方式尽量复现当时的情景 方案4 和相关测
  • Java 中使用 protobuf

    主要参考 Java 中使用 protobuf 入门基础篇 看这篇就够了 https blog csdn net wxw1997a article details 116755542 Java 中使用 protobuf 复杂深入篇 看这篇就够
  • 成都瀚网科技有限公司:抖音怎么绑定抖音小店才好?

    抖音是一款非常流行的短视频应用 为用户提供了一个展示才华 分享生活的平台 在抖音上 用户可以通过绑定抖音商店来销售自己的产品或服务 从而实现商业变现 那么 抖音如何绑定抖音商店呢 1 抖音如何绑定抖音商店 用户绑定抖音商店需要按照以下步骤操
  • PCIe专题学习——3.2(数据链路层Ack/Nak机制解析)

    之前我们讲了对PCIe的一些基础概念作了一个宏观的介绍 了解了PCIe是一种封装分层协议 packet based layered protocol 主要包括事务层 Transaction layer 数据链路层 Data link lay
  • 数据挖掘计算题-1

    一 设某事务项集构成如下表 填空完成表1中支持度和置信度的计算 1 12 15分 表1 支持度与置信度 事务ID 项集 L2 支持度 规则 置信度 T1 A D A B 1 A B 7 T2 D E A C 2 C A 8 T3 A C E
  • JavaScript 中的 `this` 指向问题与其在加密中的应用

    JS中的 this 关键字是一个非常重要的概念 它在不同情况下会指向不同的对象或值 在本文中 我们将深入探讨 JavaScript 中 this 的各种情况 并思考如何将其应用于 JS加密中的一些有趣用途 1 全局上下文中的 this 在全
  • 安卓逆向之去除app游戏入口广告

    安卓逆向学习群692903341 首先来看一下app游戏入口界面广告 lt
  • Python轻量级Web框架Flask(1)——简介/虚拟环境介绍/安装

    1 Redis简介 1 数据库分类 关系型数据库 MySQL Oracle 非关系型数据库 Redis MongoDB 2 介绍 Redis是一个开源 高级的键值存储和一个适用的解决方案 用于构建高性能 可扩展的Web应用程序 3 特点 R
  • BUUCTF [极客大挑战 2019] Http

    BUUCTF 极客大挑战 2019 Http 启动环境 主页为三叶草技术小组纳新 查看网页源码 发现隐藏的页面 div class image img src images pic01 jpg alt div div class conte
  • HTML--后台管理系统

    后台管理系统
  • [网络安全自学篇] 八十七.恶意代码检测技术详解及总结

    这是作者网络安全自学教程系列 主要是关于安全工具和实践操作的在线笔记 特分享出来与博友们学习 希望您喜欢 一起进步 前文分享了威胁情报分析 通过Python抓取FreeBuf网站 APT 主题的相关文章 这篇文章将详细总结恶意代码检测技术
  • 【SpringMVC】参数传递与用户请求和响应

    目录 一 Postman 工具使用 1 1 Postman安装 1 2 Postman的使用 1 2 1 创建WorkSpace工作空间 1 2 2 创建请求 二 参数传递 2 1 添加 Slf4j 依赖 2 2 普通传参 知识点1 Req
  • js formatDate 时间转换

    formatDate function time fmt type type 类型 0 时间为秒 1 时间为毫秒 var date new Date type 0 time 1000 time var o M date getMonth 1
  • ltconfig: you must&nbs…

    在64位机器下编译libghttp碰到的问题 libghttp是gnome下的HTTP客户端库 实现http功能 可以替换curl 的http功能 在32位的机器上编译没问题 在64位的机器上 configure 不过去 错误信息是 ltc
  • vue+C#后台上传excel处理数据

    比较简洁的excel处理方法 希望对大家有所帮助 1 界面
  • POJ - 2325 Persistent Numbers

    The multiplicative persistence of a number is defined by Neil Sloane Neil J A Sloane in The Persistence of a Number publ