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