题目:
题目有了暗示就好做多了,将数字分解成3,当余数小于三时作为递归的终止条件。
代码:
#include <bits/stdc++.h>
using namespace std;
int k=0,sum=1;
void F(int a)
{ if(a<=4)
{
k++;
cout<<a<<" ";
cout<<endl;
cout<<k<<" "<<a*sum<<endl;
}
else
{
cout<<3<<" ";
k++;
sum*=3;
F(a-3);
}
}
int main()
{ int a;
while(cin>>a)
{F(a);
sum=1;
k=0;}
return 0;
}