zoukankan      html  css  js  c++  java
  • POJ 1142 Smith Numbers

    题目出处:http://acm.pku.edu.cn/JudgeOnline/problem?id=1142

    版权声明版权归作者WeiSteven所有,转载请注明! 

    该程序时间为47ms 

    代码
     1 #include <stdio.h>
     2 #include <math.h>
     3 bool isPrimer(long d)
     4 {
     5     if(d==2||d==3||d==5||d==7||d==11||d==13)
     6     {
     7         return true;
     8     }
     9     for(int i=2;i<=sqrt((double)d);i++)
    10     {
    11         if(d%i==0)
    12         {
    13             return false;
    14         }
    15     }
    16     return true;
    17 }
    18 int getDataSum(long d)
    19 {
    20     int re=0;
    21     while(d>0)
    22     {
    23         re+=d%10;
    24         d/=10;
    25     }
    26     return re;
    27 }
    28 int getPrimerSum(long d)
    29 {
    30     int re=0;
    31     for(int i=2;d>1&&i<=sqrt((double)d);)
    32     {
    33         if(d%i==0)
    34         {
    35             re+=getDataSum(i);
    36             d/=i;
    37         }
    38         else
    39         {
    40             i++;
    41         }
    42     }
    43     return re+getDataSum(d);
    44 }
    45 
    46 int main()
    47 {
    48     freopen("in.txt","r",stdin);
    49     long data;
    50     while(scanf("%ld",&data)!=EOF&&data!=0)
    51     {
    52         while(++data)
    53         {
    54             if(!isPrimer(data)&&getDataSum(data)==getPrimerSum(data))
    55             {
    56                 printf("%ld\n",data);
    57                 break;
    58             }
    59         }    
    60     }
    61     return 1;
    62 }
  • 相关阅读:
    7. Reverse Integer
    4. Median of Two Sorted Arrays
    微服务实战系列(四)-注册中心springcloud alibaba nacos-copy
    微服务实战系列(五)-注册中心Eureka与nacos区别-copy
    Restful、SOAP、RPC、SOA、微服务之间的区别-copy
    从SOA到RPC、SOAP、REST-copy
    spring-session实现分布式集群session的共享-copy
    深入理解 RESTful Api 架构-copy
    RESTful 架构详解-copy
    SpringBoot使用MyBatis-Generator详解-copy
  • 原文地址:https://www.cnblogs.com/weisteve/p/1797756.html
Copyright © 2011-2022 走看看