当前位置:网站首页>Classic programming problem: finding the number of daffodils
Classic programming problem: finding the number of daffodils
2022-07-01 02:47:00 【Sharp blade CC】
List of articles
What is narcissus number ?
Narcissistic number (Narcissistic number) It's also called super perfect number invariant (pluperfect digital invariant, PPDI)、 Narcissistic number 、 Self idempotent 、 Armstrong number or Armstrong number (Armstrong number), The number of Narcissus refers to a 3 digit , Of the numbers in each of its bits 3 The sum of the powers is equal to itself . for example :1^3 + 5^3+ 3^3 = 153.
use C How language is implemented ?
First , Let's think about our ideas first , Here are a few steps :
1. So what we want is 0-10w The number of daffodils in the garden , Then you need to use a cycle
2. seek i The number of digits of this number
3. Decompose the number of each bit of this multi bit number, and then find the cubic power of each bit, and then find the sum
4. Judge
#include<stdio.h>
#include<math.h>
int main()
{
for(i=0;i<100000;i++)
{
int n=i;
int num=1;//num Is the number of digits of a multi digit number
while(n/10)
{
num++;// Calculate the number of digits
n=n/10;
}
n=i;// Reset n, Prevent a dead cycle
int sum=0;
while(n)
{
sum=sum+pow(n%10,num);// Calculate the sum of each bit number to the power of three
n=n/10;
}
if(sum==i)
printf("%d ",i);
}
return 0;
}
give the result as follows :
0 1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474 54748 92727 93084
In this way, we can calculate the number of daffodils ! But this process does not use function calls , Readers are expected to optimize by themselves , If you like it, remember Sanlian !
边栏推荐
- SAP ALV汇总跟导出Excel 汇总数据不一致
- UE4渲染管线学习笔记
- Poj-3486-computers[dynamic planning]
- Mouse over effect VI
- [PR # 5 A] two way running (state pressure DP)
- 如果在小券商办理网上开户安全吗?我的资金会不会不安全?
- 查看 jvm 参数
- In the industrial Internet, "small" programs have "big" effects
- [JS] [Nuggets] get people who are not followers
- Restcloud ETL WebService data synchronization to local
猜你喜欢

UE4 rendering pipeline learning notes

Machine learning 9-universal approximator radial basis function neural network, examining PDA and SVM from a new perspective

Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and

Dell服务器重启iDRAC方法

MCU firmware packaging Script Software

Share Creators萌芽人才培養計劃來了!

Gartner research: in China, the adoption of hybrid cloud has become the mainstream trend

AI 边缘计算平台 - BeagleBone AI 64 简介

Densenet network paper learning notes

Sampling Area Lights
随机推荐
Od modify DLL and exe pop-up contents [OllyDbg]
股票开户安全吗?上海股票开户步骤。
Pulsar Geo Replication/灾备/地域复制
DenseNet网络论文学习笔记
Gartner research: in China, the adoption of hybrid cloud has become the mainstream trend
详解数据治理知识体系
在国内如何买港股的股?用什么平台安全一些?
Visual effects, picture to cartoon function
How to realize the scene linkage of intelligent lock, lamp and intelligent curtain motor in zhiting?
Restcloud ETL实践之数据行列转换
Xception学习笔记
PTA 1017
Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
AI 边缘计算平台 - BeagleBone AI 64 简介
Mouse over effect III
ssh配置免密登录时报错:/usr/bin/ssh-copy-id: ERROR: No identities found 解决方法
Pychar open remote directory remote host
[PR # 5 A] two way running (state pressure DP)
Ipmitool download address and possible problems during compilation and installation
Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?