PHP calculates the number of daffodils smaller than 1000

Source: Internet
Author: User
PHP calculates the number of daffodils smaller than 1000

In programming languages, the number of daffodils is the number of n (> = 3) digits, which is equal to the sum of the n power of each number. For example, 153 is a daffodils number, 153 = 13 + 53 + 33. write a program to solve all the daffodils less than 1000.

For example, php calculates the number of daffodils less than 1000.

  1. For ($ I = 100; $ I <1000; $ I ++ ){
  2. $ A = intval ($ I/100 );
  3. $ B = intval ($ I/10) % 10;
  4. $ C = $ I % 10;
  5. If (pow ($ a, 3) + pow ($ B, 3) + pow ($ c, 3) ==$ I ){
  6. Echo $ I. "\ t ";
  7. }
  8. }
  9. ?>

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.