Narcissus number Java implementation

Source: Internet
Author: User
Tags pow

Title Description:

Spring is the season of flowers, Narcissus is one of the most charming representatives, mathematics has a number of daffodils, he is defined as:
"Narcissus number" refers to a three-digit number, its number of cubes and equal to itself, such as: 153=1^3+5^3+3^3.
It is now required to output all the number of daffodils in the M and N ranges.

input

There are multiple groups of input data, one row for each group, including two integers m and n (100<=m<=n<=999).

Output

For each test instance, it is required to output all the number of daffodils in a given range, that is, the output of daffodils must be greater than or equal to M, and less than or equal to N, if there are multiple, then the order from small to large lines in the output, separated by a space;
If the number of daffodils does not exist within the given range, the output is no;
The output for each test instance takes one row.

Sample Input

100 120
300 380

Sample Output

No
370 371

1 ImportJava.util.*;2  Public classmain{3        Public Static voidSXH (intNintm) {4            intFlag=0;5             inti;6              for(i=n;i<=m;i++){7                   intsum;8                   intg=i%10;//Digit9                   ints=i/10%10;//10 GuestsTen                   intb=i/100;//Hundred OneSum= (int) Math.pow (g,3) + (int) Math.pow (s,3) + (int) Math.pow (b,3); A                   if(sum==i) -{System.out.print (i+ "")); -Flag=1; the                   } -             } -             if(flag==0){ -System.out.println ("No")); +             } -              +       } A        Public Static voidMain (String args[]) { atScanner in=NewScanner (system.in); -              while(In.hasnext ()) { -                   intn=in.nextint (); -                   intm=in.nextint (); - sxh (n,m); -             } in       } -}

Narcissus number Java implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.