码迷,mamicode.com
首页 > 其他好文 > 详细

51Nod 1015 水仙花数

时间:2017-07-26 14:45:23      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:int   cout   using   black   ring   clu   turn   name   整数   

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

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #include <cstring>
 5 using namespace std;
 6 #define ll long long
 7 int main()
 8 {
 9     int n;
10     cin>>n;
11     for(int i=n; ;i++){
12         if(i<1000){
13             int a=i/100;
14             int b=(i-a*100)/10;
15             int c=i%10;
16             if(a*a*a+b*b*b+c*c*c==i){
17                 cout<<i<<endl;
18                 break;
19             }
20         }
21         else if(i>=1000){
22             int a=i/1000;
23             int b=(i-a*1000)/100;
24             int c=(i-a*1000-b*100)/10;
25             int d=i%10;
26             if(a*a*a*a+b*b*b*b+c*c*c*c+d*d*d*d==i){
27                 cout<<i<<endl;
28                 break;
29             }
30         }
31     }
32     return 0;
33 }

 

51Nod 1015 水仙花数

标签:int   cout   using   black   ring   clu   turn   name   整数   

原文地址:http://www.cnblogs.com/shixinzei/p/7239224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!