当前位置:网站首页>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 !
边栏推荐
- Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel
- 阿里天池SQL学习笔记——DAY3
- From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)
- ROS知识点——消息过滤器 ( message_filters)
- SSB threshold_ SSB modulation "suggestions collection"
- USB interface powered Bluetooth color light strip controller
- Qwebengineview crash and alternatives
- 13、Darknet YOLO3
- Five reasons to choose SAP Spartacus as the implementation framework of SAP commerce cloud storefront
- Sword finger offer 26 Substructure of tree
猜你喜欢
![链表求和[dummy+尾插法+函数处理链表引用常见坑位]](/img/08/30e8ca2376104d648a82dca8a72c42.png)
链表求和[dummy+尾插法+函数处理链表引用常见坑位]

Experience home office, feel the completion of the project | community essay solicitation

chrome瀏覽器快速訪問stackoverflow

Easyswoole3.2 restart failed

每日一题——小乐乐改数字

Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity

Navigateur Chrome pour un accès rapide au stackoverflow

Use of nexttile function in MATLAB

easyswoole3.2重启不成功

Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
随机推荐
VScode知识点——常见报错
SAP commerce Cloud Architecture Overview
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
How to create a new page for SAP Spartacus storefront
详细介绍scrollIntoView()方法属性
About me
Idea2021.1 installation tutorial
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
uniapp H5页面调用微信支付
Blog theme "text" summer fresh Special Edition
IPtables中SNAT、DNAT和MASQUERADE的含义
Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel
Si446 usage record (II): generate header files using wds3
traceroute命令讲解
Shutter: action feedback
书包网小说多线程爬虫[通俗易懂]
List summation [dummy+ tail interpolation + function processing list reference common pit]
One year is worth ten years
求简单微分方程
Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity