#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
int a_array[18] = { 57,71,87,97,99,101,103,113,114,115,128,129,131,137,147,156,163,186 };
int result[18] = { 0 };
void recursive(int level, int sum) {
if (17 < level) { return; }
int i = 0;
while (1) {
int next_sum = sum - i * a_array[level];
if (next_sum > 0) {
result[level] = i;
recursive(level + 1, next_sum);
}
else if (next_sum == 0) {
static int x;//静态变量
result[level] = i;
int j,sum=0;
x++;
printf("第%d种情况: ",x);
for(j = 0 ; j < 18 ;j++) {
if(j==17)
printf("%d*%d =", result[j], a_array[j]);
else
printf("%d*%d +",result[j],a_array[j]);
sum+=result[j]*a_array[j];
}
printf("=%d\n",sum);
return;
}
else {
return;
}
++i;
}
}
int main() {
recursive(0, 1000);
}
|