惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
H
Help Net Security
V
Visual Studio Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
The Cloudflare Blog
Martin Fowler
Martin Fowler
D
Docker
腾讯CDC
F
Fortinet All Blogs
雷峰网
雷峰网
GbyAI
GbyAI
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - 叶小钗

博客园 - saintqdd

hdu 1102 pku 2421 解题报告 pku 2777 Count Color 解体报告 石子合并问题 nkoj1139和乘积最大那题一样. A Tour in Loquat Orchard (FZU 2007 ICPC Qualification Round I tzw) 最大黑区域 滑雪 一道经典题,humble number 今天碰到了一个很诡异的题,Alphacode (zoj 2202) 这两天经常碰到dp题,就写了一个0-1背包 实训以来,到这里的次数少了! 郁闷,乘积最大那题WA原来只是因为我用了pow函数引起的! POJ强烈推荐50题 JOJ 2391 words POJ 1014 三十分钟掌握STL STL学习小记 POJ1006,中国剩余定理 POJ1003,简单题
Smith Number
saintqdd · 2007-08-07 · via 博客园 - saintqdd

Description

1982年,Lehigh大学的数学家Albert Wilansky在查看电话簿的时候,突然发现他的姐夫H.Smith的电话号码有一个很特别的性质:该数字的所有位数之和,等于该数所有质因子的位数之和
4937775 = 3 * 5 * 5* 65837
4937775的位数和为:
4+9+3+7+7+7+5 = 42
而该数所有质因子的位数之和为:
3+5+5+(6+5+8+3+7) = 42
于是Albert Wilansky将有这种性质的数叫做Smith number。很显然,质数都有这种性质,所以他把质数排除在外。
而你所要做的,是判断所给的数是否为Smith number。

此题意思很清楚,输入一个数,求出其质因子的位数之和,然后判断是否和原数的位数之和相等,质数排除在外,因为任何一个数(大于2的数)除了质数都可以写成一系列的从小的大的质数的乘的形式,所以对于每一个数都做这样的计算,从i(i>=2)开始遍历,如果这个数对i取摸等于0,那么将这个数除以i,直到取摸i不等于0,纪录i的个数,然后在计算一个i的位数之和,总的位数和为(个数*一个的位数之和),然后i++,i的上界为sqrt(n+0.0),当然最后还要做一个判断,这个数是否是质数,这可以在循环中加一个标记来判断是否有因子;如果是质数,最后n是否是1,如果不是加上这个数的位数之和,否则跳过。

my code:

#include<stdio.h>
#include<math.h>
int main(){
    int n;
    while(scanf("%d",&n)&&n!=0){
        if(n==1||n==2){
            puts("No");
            continue;
        }
        int ws=0,zws=0,t,i;
        t=n;
        while(t>0){
            ws+=t%10;
            t/=10;
        }
        int f=0;
        for(i=2;i<=(int)sqrt(n+0.0);i++){
            int ic=0,iws=0;
            if(n%i==0){
                f=1;
                while(n%i==0&&n>0){
                    ic++;
                    n/=i;
                }
                t=i;
                while(t>0){
                    iws+=t%10;
                    t/=10;
                }
                zws+=ic*iws;
            }
        }
        if(f){
            if(n!=1){
                while(n>0){
                    zws+=n%10;
                    n/=10;
                }
            }
        }
        else{
            puts("No");
            continue;
        }
        if(zws==ws)
            puts("Yes");
        else
            puts("No");
    }
}