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

推荐订阅源

B
Blog RSS Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed
D
Docker
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
Forbes - Security
Forbes - Security
MongoDB | Blog
MongoDB | Blog
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
A
About on SuperTechFans
Schneier on Security
Schneier on Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
IT之家
IT之家
The Last Watchdog
The Last Watchdog
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
Project Zero
Project Zero
B
Blog
Recorded Future
Recorded Future
博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
T
Threatpost
H
Heimdal Security Blog
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog

博客园 - 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");
    }
}