Algorithm training 4-3 Daffodils number time limit: 1.0s memory Limit: 256.0MB problem description Print all daffodils between 100 and 999. The so-called Narcissus number refers to the number of cubes that satisfy them and the integers for the number itself, such as 153=1^3+5^3+3^3. Sample input An input example that satisfies the requirements of the topic.
Cases:
No sample output 153
Xxx
Xxx
Topic Analysis:
This is a simple problem of brute force cracking. Simply break down the hundred, 10, and digits of each three-digit number, and then calculate whether the cubic is equal to the number. Example code:
1 Public classMain {2 Public Static voidMain (string[] args) {3 for(inti = 153; i < 1000; i++){4 intA = i/100;//Hundred5 intb = i% 100/10;//10 Guests6 intc = i% 10;//Digit7 if(i = = (Math.pow (a,3) +math.pow (b,3) +math.pow (c,3))){8 System.out.println (i);9 }Ten } One } A}
Blue Bridge Cup algorithm training ALGO-147 4-3 daffodils number