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
- i + j + k = 100
- 5*i + 3*j + K/3 = 100
By the above two equations we can launch:
- j = 25-i * 7/4;
- 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