//雄雞爲7元/只,母雞爲5元/只,小雞爲1元/3只,如果100元 100只雞中包含 雄雞,母雞,小雞。各多少隻呢?
#include<iostream>
using namespace std;
int main (){
//雄雞最高耗用金額爲 100-5-1 =94元,取7的倍數,得91元,雄雞數的範圍爲1~13只
//雄雞數
for(int cock=1;cock<=13;++cock)
//母雞最高耗用金額爲100-7-1=92元,取92%5~18,母雞數的範圍爲1~18只
for(int hen=1;hen<=18;++hen)
//小雞最高耗用金額爲100-7-5 = 88元,去88%1*3=264只,由於限制只能買<=98只,但是 小雞隻能爲3的倍數所以 只有96只;
for(int chick=1;chick<=96;++chick){
if(7*cock+hen*5+chick/3-100) continue;
if(cock+hen+chick-100) continue;
if(chick%3) continue;
cout << "Cock:"<<cock<<",Hens:"<<hen<<",Chicks:"<<100-cock-hen<<endl;
}
}
輸出: