M - 完美立方
题目: Sample Input 24 Sample Output Cube = 6, Triple = (3,4,5) Cube = 12, Triple = (6,8,10) Cube = 18, Triple = (2,12,16) Cube = 18, Triple = (9,12,15) Cube = 19, Triple = (3,10,18) Cube = 20, Triple = (7,14,17) Cube = 24, Triple = (12,16,20)
#include<stdio.h>
int s(int a)
{
return a*a*a;
}
int main()
{
int a=6,b=3,c=4,d=5,n;
scanf("%d",&n);
while(a<=n)
{
if (s(a)==s(b)+s(c)+s(d)&&b<=c&&c<=d)
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
d++;
if (d>n)
{
d=2;
c++;
}
if (c>n)
{
c=2;
b++;
}
if (b>n)
{
b=2;
a++;
}
}
return 0;
}
|