Huawei OJ Platform--hundred money to buy hundred chicken problem

Source: Internet
Author: User

Title Description:

Yuanmai Fifth century, the ancient Chinese mathematician Zhang Chujian in the Book of "The Hundred Chicken Problem": the chicken Weng A value of five, chicken mother a valuable three, chickens three valuable one.

Hundred money buys hundred chicken, asks the chicken Weng, the chicken mother, chickens each geometry?

Ideas:

This question is very simple, suppose the chicken Weng I only, chicken mother J only, then has

    1. i + j + k = 100
    2. 5*i + 3*j + K/3 = 100

By the above two equations we can launch:

    1. j = 25-i * 7/4;
    2. K = 3/4 + i *;

Because I, j, K must be 0 or a positive integer, so I must be a multiple of 4, so we are in the following program is a 4-step growth

1  Public classBuyhens {2 3      Public Static voidMain (string[] args) {4         inti = 0 ;5         intj = 0 ;6         intK = 0 ;7         8          for(i = 0; 5*i <=; i + = 4){9j = 25-I*7/4 ;TenK = + I*3/4 ; One             //conditions are met J >= 0 && k >= 0 A             if(J >= 0 && k >= 0 ){ -SYSTEM.OUT.PRINTLN (i + "" + j + "" +k); -             }             the         }     -     } -}

Huawei OJ Platform--hundred money to buy hundred chicken problem

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.