51Nod 1015 水仙花數
阿新 • • 發佈:2017-07-26
efi bre clu mes long bsp long long cout pan
水仙花數是指一個 n 位數 ( n >= 3 ),它的每個位上的數字的 n 次冪之和等於它本身。(例如:1^3 + 5^3 + 3^3 = 153)
給出一個整數M,求 >= M的最小的水仙花數。
Input
一個整數M(10 <= M <= 1000)Output
輸出>= M的最小的水仙花數Input示例
99Output示例
153
1 #include <iostream> 2 #include <algorithm> 3 #include <stdio.h> 4 #include <cstring> 5using 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 水仙花數