Find all daffodil numbers and check if a three-digit number is a daffodil number

Brief introduction: The daffodil number is the so-called Armstrong number, which means that the cube sum of a three-digit number is equal to the number itself, for example: 153=1*1*1+5*5*5+3*3 *3; 370=3*3*3+7*7*7+0*0*0;

Idea: Define a three-digit number, separate its ones, tens, and hundreds, use the hundreds to find the remainder of 1000, and then divide by 100; use the tens to find the remainder of 100, and then divide by 10; use the ones Find the remainder of 10 and divide by 1;

Method: Define three numbers a, b, and c, and then define n=0, let a calculate the remainder of 1000 and divide it by 100, then let b calculate the remainder of 100 and divide it by 10, and let c calculate the remainder of 10 Then divide by 1, then define a y=a*a*a+b*b*b+c*c*c, and then judge y to see if y is equal to n, and if y is equal to n then Counting for the daffodils, if you don't want to wait, then not.

 The same is true for checking whether a three-digit number is a daffodil number, and the code will not be explained one by one;

Guess you like

Origin blog.csdn.net/m0_65208770/article/details/127866609