# 数学趣题_父亲分羊

## 二、题目分析

#include<stdio.h>
#include<math.h>
int main()
{
int n,x,y,z,counter;
for(x = 1;x < 50;x++){
for(y = 1;y < 50;y++){
for(z = 1; z < 50;z++){
for(n = 1;n < 50;n++){
//判断条件 1，等式成立；2，x y z 三个值不相等；3，n要大于 x y z三个任一的值；4，x > y > z
if(((n+1)*(y*z + x*z + x*y) == n*x*y*z) && (x != y && x != z && y!=z) && (((n+1) >= x && (n+1) >= y && (n+1) >= z))) {
if ((x>y && y>z) && ((n+1)%x == 0 && (n+1)%y == 0 && (n+1)%z == 0)){
printf("n=%d,x=%d,y=%d,z=%d\n",n,x,y,z);
counter++;
}
}
}
}
}
}

printf("满足条件的(n, x, y, z)为%d\n",counter);

return 0;
}

/*
Output
n=19,x=5,y=4,z=2
n=11,x=6,y=4,z=2
n=41,x=7,y=3,z=2
n=23,x=8,y=3,z=2
n=17,x=9,y=3,z=2
n=14,x=10,y=3,z=2

*/

posted @ 2018-12-19 19:50  Zoctopus_Zhang  阅读(270)  评论(0编辑  收藏
// function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; \$("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);