#include <cstdio> #include <iostream> using namespace std; int N; int main() { cin>>N; int res = N; for (int i = 0; i <= N; i++) { int c1 = 0, c2 = 0; int t = i; while (t > 0) c1 += t % 6, t /= 6; t = N - i; while (t > 0) c2 += t % 9, t /= 9; cout<<"("<<i<<"->"<<c1<<","<<N-i<<"->"<<c2<<")"; cout<<" -> "<<c1+c2<<"\n"; if (res > c1+c2) res = c1+c2; } cout<<res; }
20
(0->0,20->4) -> 4 (1->1,19->3) -> 4 (2->2,18->2) -> 4 (3->3,17->9) -> 12 (4->4,16->8) -> 12 (5->5,15->7) -> 12 (6->1,14->6) -> 7 (7->2,13->5) -> 7 (8->3,12->4) -> 7 (9->4,11->3) -> 7 (10->5,10->2) -> 7 (11->6,9->1) -> 7 (12->2,8->8) -> 10 (13->3,7->7) -> 10 (14->4,6->6) -> 10 (15->5,5->5) -> 10 (16->6,4->4) -> 10 (17->7,3->3) -> 10 (18->3,2->2) -> 5 (19->4,1->1) -> 5 (20->5,0->0) -> 5 4