zoukankan      html  css  js  c++  java
  • 51nod 1015 水仙花数

    水仙花数是指一个 n 位数 ( n >= 3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)
    给出一个整数M,求 >= M的最小的水仙花数。
     
    Input
    一个整数M(10 <= M <= 1000)
    Output
    输出>= M的最小的水仙花数
    Input示例
    99
    Output示例
    153

    枚举
    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    
    using namespace std;
    
    int m,i,j;
    int powe(int a,int b)
    {
        int base=a,r=1;
        while(b)
        {
            if(b&1)
            r*=base;
            base*=base;
            b>>=1;
        }
        return r;
    }
    int main()
    {
        int t;
        cin>>m;
        for(i=m;i<=10000000;++i)
        {
            if(i>=100&&i<=999) t=3;
            else if(i>=1000&&i<=9999) t=4;
            else if(i>=10000&&i<=99999) t=5;
            else if(i>=100000&&i<=999999) t=6;
            else if(i>=1000000&&i<=9999999) t=7;
            int sum=0;
            int j=i;
            while(j)
            {
                sum+=powe(j%10,t);
                j/=10;
            }
            if(sum==i)
            {
                cout<<i<<endl;
                return 0;
            }
        }
    }
    我们都在命运之湖上荡舟划桨,波浪起伏着而我们无法逃脱孤航。但是假使我们迷失了方向,波浪将指引我们穿越另一天的曙光。
  • 相关阅读:
    万丈高楼平地起
    @synthesis 使用的时候注意的地方
    arc4random()
    Whereami: CLLocationManager not calling delegate
    总结
    生病两日,真是难受
    Xcode 5 Error CertUIFramework.axbundle
    c++笔记 重要的声明
    class
    检查没有错误或警告
  • 原文地址:https://www.cnblogs.com/ruojisun/p/6378600.html
Copyright © 2011-2022 走看看