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. 概率-拒绝采样 Rejection Sampling

    2018-12-09 16:40:30 一.使用Rand7()来生成Rand10() 问题描述: 问题求解: 这个问题字节跳动算法岗面试有问到类似的,有rand6,求rand8,我想了好久,最后给了一 ...

  2. Centos单机部署Elasticsearch7.2集群

    配置node0 # ======================== Elasticsearch Configuration ========================= # # NOTE: E ...

  3. Hive支持的文件格式和压缩格式及各自特点

    Hive中的文件格式 1-TEXTFILE 文本格式,Hive的默认格式,数据不压缩,磁盘开销大.数据解析开销大. 对应的hive API为:org.apache.hadoop.mapred.Text ...

  4. 你能在泰坦尼克号上活下来吗?Kaggle的经典挑战

    Kaggle Kaggle是一个数据科学家共享数据.交换思想和比赛的平台.人们通常认为Kaggle不适合初学者,或者它学习路线较为坎坷. 没有错.它们确实给那些像你我一样刚刚起步的人带来了挑战.作为一 ...

  5. webpack配置打包vue文件

    1.首先全局安装node,和npm.检查是否安装成功 2.新建一个文件下,进入该文件夹. 前先执行 npm init -y 然后就会在文件夹下出现一个package.json文件 然后执行 npm i ...

  6. POJ - 3255 SPFA+邻接表求次短路径

    题意:给出m条边 , n个顶点,u [ i ]到v [ i ] 的距离w [ i ],求除了最短路的那条最短的边的长度. 思路:之前有做过相似的题,使用迪杰斯特拉算法求单源最短路径,并且记录路径,枚举 ...

  7. AI体验类产品竞品分析

    1.业界状态 人工智能(Artificial Intelligence),简称AI.上个世纪50年代就有一批年轻的科学家提出了这一概念,经历过50多年的长足发展,信息化建设的脚步不断加快,机器人战胜人 ...

  8. 搞定SEO,看这一篇就够了

    一.SEO入门 1.SEO是什么? SEO(Search Engine Optimization)中文意思为搜索引擎优化.在了解搜索引擎自然排名机制的基础上,对网站进行内部及外部的调整优化,改进网站在 ...

  9. LVS的部署、案例、以及常见问题

    LVS的部署.案例.以及常见问题 原创chenhuyang 最后发布于2018-06-03 16:18:25 阅读数 1560 收藏 展开 一.LVS的部署 LVS现在已经集成在linux内核模块中, ...

  10. Codeforces 1322C - Instant Noodles(数学)

    题目链接 题意 给出一个二分图, 两边各 n 个点, 共 m 条边, n, m ≤ 5e5. 右边的点具有权值 \(c_i\), 对于一个只包含左边的点的点集 S, 定义 N(S) 为所有与这个点集相 ...