The number of daffodils is also called Armstrong number.
Narcissus number refers to an n-digit number (n≥3) , and the sum of the n power of the number on each bit of it is equal to its own. (Example: 1^3 + 5^3 + 3^3 = 153)
Ask if the number you entered is a daffodil number
This problem corrected me a wrong understanding, I always thought that the number of daffodils is the cubic and equal to the number of each person, because it is often asked for a three-digit number.
The full out code is as follows:
#include "oj.h"//function: Determine whether the input Nvalue is Narcissus number//input: Nvalue is a positive integer//output: no//return: If the input is Narcissus number, return 1, otherwise return 0unsigned int isdaffodilnum ( unsigned int nvalue) {if (nvalue<100) return 0;long n=nvalue;long sum=0;int i;int cnt=0;int tmp=1;while (Nvalue) {nvalue/=10;cnt++;} Nvalue=n;while (nvalue) {tmp=1;i=nvalue%10;for (int j=0;j<cnt;j++) {tmp*=i;} sum+=tmp;nvalue/=10;} if (sum==n) return 1; else return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Number of daffodils