题解:首先 1,2,3肯定无法凑出24,其次,因为24 * 1 = 24,且n=4的时候一定能凑出24,所以4+2k的所有数都能凑出24,(k为正整数)。而对于奇数,我们发现n=5的时候也能凑出24,所以可知5+2k的所有数也能凑出24(k为正整数)。这样我们得出结论:n>=4的时候都可以凑出24,n<4的数都无法凑出24。
#include <iostream>
#include <cstdio>
using namespace std;
int n;
int main()
{
scanf("%d",&n);
if (n<4)
{
cout <<"NO"<<endl;
return 0;
}
else
{
cout <<"YES"<<endl;
if (n%2==0)
{
int i=n;
while (i>4)
{
printf("%d - %d = %d\n",i,i-1,1);
i=i-2;
}
printf("2 * 3 = 6\n");
printf("6 * 4 = 24\n");
for (int i=1;i<=(n-4)/2+1;i++) printf("24 * 1 = 24\n");
}
else
{
int i=n;
while (i>5)
{
printf("%d - %d = %d\n",i,i-1,1);
i=i-2;
}
printf("1 + 5 = 6\n");
printf("6 * 3 = 18\n");
printf("18 + 2 = 20\n");
printf("20 + 4 = 24\n");
for (int i=1;i<=(n-5)/2;i++) printf("24 * 1 = 24\n");
}
}
return 0;
}