用1,2....9组成三个三位数abc,def,ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3,输出所有解
用1,2....9组成三个三位数abc,def,ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3,输出所有解
程序代码:#include
using namespace std;
int f1(int a)
{
int b=0;
while(a)
{
int n=a%10;
a/=10;
b+=n;
}
return b;
}
int f2(int a)
{
int c=1;
while(a)
{
int n=a%10;
a/=10;
c*=n;
}
return c;
}
int main()
{
for(int i=123; i<=987/3; i++)
{
if( f1(i)+f1(2*i)+f1(3*i)==45 && f2(i)*f2(i*2)*f2(i*3)==362880)
cout << i<<" "<<2*i<<" "<<3*i << endl;
}
return 0;
}
