当前位置:网站首页>Daily question - "number of daffodils"
Daily question - "number of daffodils"
2022-07-02 17:39:00 【Protect Xiaozhou】
Hello, everyone , I'm protecting Xiao Zhou ღ, What this issue brings to you is seeking “ Narcissistic number ”, This daffodil , Not that daffodil , Let's have a look ~

subject :
Find out 0~100000 Between all “ Narcissistic number ” And the output .
describe :
“ Narcissistic number ” It means a n digit , Of its digits n The sum of the powers is just equal to the number itself , Such as :153=1^3+5^3+3^3, be 153 It's a “ Narcissistic number ”.
The scope of attention is 0~100000 Between all that match the description “ Narcissistic number ”.
Thinking analysis :
Based on the description , We know , Your numbers are n Only when the sum of the powers is just equal to the number itself can it be called “ Narcissistic number ”, First try to judge whether a number is daffodil number , How to judge ?
First step : Find the number of digits n.
The second step : Find the n The sum of the powers .
The third step : Judge the number n Whether the sum of the powers is just equal to the number itself
This blogger brings you two ways to solve problems , It's all the same , Ordinary counting , Recursive count .
Ordinary counting :
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
// Count the number of digits of each number
int Count(int size)
{
int n = 0;
while (size)
{
size = size / 10;
++n;
}
return n;
}
// Judge whether it is daffodil
int IfDaffodil(int i,int n)
{
int size = i;
int sum = 0;
// Judge whether it meets “ daffodils ”
while (size!=0)
{
int ssum = 1;
//ssum Count each person's n Power
for (int j = 0; j < n; j++)
{
ssum *= size % 10;
}
size = size / 10;
//sum Statistics for everyone n The sum of the powers
sum += ssum;
}
// Your numbers are n The sum of the powers is exactly equal to the number itself
if (sum == i)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
// Ergodic interval
for (int i = 0; i <= 100000; ++i)
{
// When the program is executed IfDaffodil when , Will first perform as “ Parameters ” Of Count, etc. Count Execute yourself after execution
int size=IfDaffodil(i, Count(i));
if (size == 1)
{
printf("%d ",i);
}
else
{
continue;
}
}
return 0;
}
Recursive count :
#include<stdio.h>
// Count the number of digits of each number
int Count(int n)
{
if (n < 10)// When there is only one digit left in the number , Recursion ends
return 1;
else
return Count(n / 10) + 1;
/*
{
n=n/10;
return Count(n)+1;
}
*/
}
// Calculate the number of each digit n Power
int Pow(int x, int n)
{
if (n == 0)
return 1;
else
return pow(x, --n) * x;//x^n
}
int main()
{
// Ergodic interval
for (int i = 0; i < 100000; ++i)
{
int n = i;
int sum = 0;
// Judge whether it meets “ daffodils ”
while (n)
{
//n % 10 Get the last one , Then find the power according to its own digits
sum += (Pow((n % 10), Count(i)));//Pow Calculate the number of each digit n Power
n /= 10;
}
if (sum == i)
{
printf("%d ", sum);
}
else
{
continue;
}
}
return 0;
}
Interested friends can use the blogger's method , Or do this problem in your own way .
Share a similar topic on Niuke website , You can also try to do it .
link : Narcissistic number _ Niuke Tiba _ Cattle from
Thank you for watching this article , Please look forward to : Protect Xiao Zhou ღ **,°*:.*( ̄▽ ̄)/$:*.°**

If there is infringement, please contact to modify and delete !
边栏推荐
- Map集合详细讲解
- 如何给 SAP Spartacus Storefront 创建新的页面
- Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
- AtCoder Beginner Contest 237 VP补题
- Introduction to nexus and detailed tutorial of Xiaobai using idea to package and upload to nexus3 private server
- chrome瀏覽器快速訪問stackoverflow
- Configure lamp+supervisor
- Simple linear programming problem
- ROS knowledge point - message_filters
- Smart trash can (V) - light up OLED
猜你喜欢

【网络是怎样连接的】第六章 请求到达服务器以及响应给客户端(完结)

【目标跟踪】|SiamFC

Qwebengineview crash and alternatives

si446使用记录(一):基本资料获取

The difference of message mechanism between MFC and QT

【GAMES101】作业4 Bézier 曲线

Blog theme "text" summer fresh Special Edition

From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)

easyswoole3.2重启不成功

Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
随机推荐
微信小程序 —— 上下浮动的箭头
Sword finger offer 22 The penultimate node in the linked list
Migrate your accelerator based SAP commerce cloud storefront to Spartacus
简单线性规划问题
How to quickly distinguish controlled components from uncontrolled components?
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
POJ - 1458 Common Subsequence(最长公共子序列)
chmod命令原理及用法详解[通俗易懂]
871. Minimum refueling times
牛客 JS3 分隔符
阿里天池SQL学习笔记——DAY3
牛客JS2 文件扩展名
【目标跟踪】|SiamFC
The beginning of life
ROS knowledge point - message_filters
例题 非线性整数规划
Configure lamp+supervisor
Schoolbag novel multithreaded crawler [easy to understand]
Timing / counter of 32 and 51 single chip microcomputer
简单介绍BASE64Encoder的使用