While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits of that number was equal to the sum of the digits of the prime factors of that number. Got it? Smith's telephone number was 493-7775. This number can be written as the product of its prime factors in the following way: 
4937775= 3*5*5*65837
The sum of all digits of the telephone number is 4+9+3+7+7+7+5= 42,and the sum of the digits of its prime factors is equally 3+5+5+6+5+8+3+7=42. Wilansky was so amazed by his discovery that he named this kind of numbers after his brother-in-law: Smith numbers. 
As this observation is also true for every prime number, Wilansky decided later that a (simple and unsophisticated) prime number is not worth being a Smith number, so he excluded them from the definition. 
Wilansky published an article about Smith numbers in the Two Year College Mathematics Journal and was able to present a whole collection of different Smith numbers: For example, 9985 is a Smith number and so is 6036. However,Wilansky was not able to find a Smith number that was larger than the telephone number of his brother-in-law. It is your task to find Smith numbers that are larger than 4937775!

Input

The input file consists of a sequence of positive integers, one integer per line. Each integer will have at most 8 digits. The input is terminated by a line containing the number 0.

Output

For every number n > 0 in the input, you are to compute the smallest Smith number which is larger than n,and print it on a line by itself. You can assume that such a number exists.

Sample Input

4937774
0
题目大意:
给你一个数,求大于这个数字并满足以下条件的最小值:
    条件:数字的各个位置加起来与用质数拆分该数字后得到的数字的各个位置之和相等 4937775= 3*5*5*65837
暴力模拟就可以啦 首先要知道质数拆分,然后将得到的每个数字的各个位置相加相等。如果与原数字相等的话说明找到啦!
#include<iostream>
#include<cstdio>
using namespace std; int check(int x){//由于数字范围太大,不能打表,只能这样一步一步来
for(int i=;i*i<=x;i++){
if(x%i==) return ;
}
return ;
} int f2(int x){
int sum=;
while(x){
sum+=x%;
x=x/;
}
return sum;
}
int f(int x){
int sum=;
for(int i=;i*i<=x;i++){//拆分
if(x%i==){
int ans=;
if(i<)
{
while(x%i==){
ans++;
x=x/i;
}
sum+=i*ans;
}
else {
int s=f2(i);
while(x%i==){
ans++;
x=x/i;
}
sum+=s*ans;
}
}
}
if(x>) sum+=f2(x);
return sum;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF&&n){
for(int i=n+;;i++){
if(check(i)==){
if(f2(i)==f(i)){
printf("%d\n",i);
break;
} }
}
}
return ;
}

A - Smith Numbers POJ的更多相关文章

  1. Smith Numbers POJ - 1142 (暴力+分治)

    题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路 ...

  2. Smith Numbers POJ - 1142 暴力递归枚举

    题意: 给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果   x的每一数位的和   等于  x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数 示例: ...

  3. POJ 1142 Smith Numbers(史密斯数)

    Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...

  4. poj 1142 Smith Numbers

    Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh U ...

  5. POJ 1142:Smith Numbers(分解质因数)

                                   Smith Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  6. Smith Numbers - PC110706

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10042.html 原创:Smit ...

  7. poj1142 Smith Numbers

    Poj1142 Smith Numbers Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13854 ...

  8. UVA 10042 Smith Numbers(数论)

    Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematicia ...

  9. Smith Numbers(分解质因数)

    Smith Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14173   Accepted: 4838 De ...

随机推荐

  1. 2020 python web开发就业要求锦集

    郑州 Python程序员 河南三融云合信息技术有限公司 6-8k·12薪 7个工作日内反馈 郑州 1个月前 本科及以上2年以上语言不限年龄不限 微信扫码分享 收藏 Python程序员 河南三融云合信息 ...

  2. ELK 环境搭建总结

    开始动手前的说明 我搭建这一套环境的时候是基于docker搭建的,用到了docker-compose,所以开始前要先安装好docker . docker-compose,并简单的了解docker . ...

  3. js Object方法小结

    1. Object.defineProperty(obj,prop,{                 value:...,                 writable:boolean,//可写 ...

  4. Java系列之数组

    原文首发于微信公众号:jzman-blog,欢迎关注交流! 本来打算温习一下注解方面的内容作为今天的推送,但是来不及写了,那就一起来看一下数组,数组是用来存放一组具有相同类型数据的数据结构,通过下标来 ...

  5. 监控一姐Grafana你可认识?

    我们先来认识一下格拉法纳——Grafana. 我去,这不就是实时监控大屏吗?记得 N 年前,部门为了做这么个功能,还花重金请专业公司搞过类似的图,现在想想其实也很简单呀. 话又说回来,其实 Grafa ...

  6. SpringBoot系列之RabbitMQ使用实用教程

    SpringBoot系列之RabbitMQ使用实用教程 @ 目录 1. 消息队列概述 1.1 MQ的概述 1.2 MQ目的地形式 2. 消息队列实现方式 2.1 常见MQ框架 2.2 MQ实现方式 3 ...

  7. Elasticsearch7.6学习笔记1 Getting start with Elasticsearch

    Elasticsearch7.6学习笔记1 Getting start with Elasticsearch 前言 权威指南中文只有2.x, 但现在es已经到7.6. 就安装最新的来学下. 安装 这里 ...

  8. STM32F103ZET6独立看门狗

    1.IWDG简介 STM32F103ZET6的独立看门狗(IWDG)是由内部LSI(内部约40KHZ低速时钟)时钟驱动的.由于IWDG是由内部低速时钟驱动,所以就算主时钟发生故障,IWDG依然能够工作 ...

  9. 【mysql】mysql优化

    一,表设计 1.1. E-R(entity relation)实体关系图 长方形 实体 表 椭圆形 属性 字段 菱形 关系 一对一 多对一 属于 多对多 1.2. 三范式标准 原子性 个人信息 省市县 ...

  10. 【物理】AABB物理碰撞检测

    什么是AABB? AABB,指轴对齐包围盒(Axis-aligned bounding boxes).在3D空间中,AABB是一个长方体,在2D空间中是一个长方形.特征是面法线皆平行于坐标轴,即当物体 ...