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

     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 }
  • 相关阅读:
    线程高并发
    29(套接字)就是网络编程
    28线程
    27 枚举
    26静态导入和可变参数
    25JDK新特性
    25断言 assert关键字
    24单元测试 junit
    炫酷CSS
    PHP 汉字转拼音类
  • 原文地址:https://www.cnblogs.com/wydxry/p/7239224.html
Copyright © 2011-2022 走看看