zoukankan      html  css  js  c++  java
  • hdu 1333水题

    刚看的时候还以为挺难的,试了一下最水的方法,居然过了。就是从N以后往下试,试到smith数停止就行,而且对于smith数的判断也可以简单处理,循环到sqrt(n)即可,唉,这种简单方法我这次现场赛咋没想到呢……

    /*
     * hdu1333/win.cpp
     * Created on: 2012-10-27
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    int getbitsum(int n) {
        int ret = 0;
        while(n > 0) {
            ret += n % 10;
            n /= 10;
        }
        return ret;
    }
    bool isSmith(int n) {
        int sum1 = getbitsum(n);
        int sum2 = 0;
        int sqrtn = (int)sqrt(n);
        bool isprime = true;
        for(int i = 2; i <= sqrtn; i++) {
            while(n % i == 0) {
                isprime = false;
                sum2 += getbitsum(i);
                n /= i;
            }
            if(n == 1) {
                break;
            }
        }
        if(n > 1) {
            sum2 += getbitsum(n);
        }
        return sum1 == sum2 && !isprime;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int n;
        while(scanf("%d", &n) == 1 && n > 0) {
            do{
                n++;
            }while(!isSmith(n));
            printf("%d\n", n);
        }
        return 0;
    }
  • 相关阅读:
    html调用php
    MySQL安装下载
    MySQL默认安装下载
    MySQL安装下载
    搭建php环境
    面试官:聊聊对Vue.js框架的理解
    TCP、UDP、HTTP、SOCKET之间的区别与联系
    HTTP/1、HTTP/2、HTTP/3
    git教程
    从jQuery到Serverless,前端十四年挖了多少坑?
  • 原文地址:https://www.cnblogs.com/moonbay/p/2742357.html
Copyright © 2011-2022 走看看