Advertisement
vov44k

t2963

Sep 18th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. package t2022_09_12;
  2. import java.util.Scanner;
  3.  
  4. public class t2963 {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner in = new Scanner(System.in);
  8.         int n = in.nextInt();
  9.         int[] arr = new int[n + 1];
  10.         arr[1] = 0;
  11.         for (int i = 2; i <= n; i++) {
  12.             int min = arr[i - 1];
  13.             if (i % 2 == 0) {
  14.                 min = Math.min(min, arr[i / 2]);
  15.             }
  16.             if (i % 3 == 0) {
  17.                 min = Math.min(min, arr[i / 3]);
  18.             }
  19.             arr[i] = min + 1;
  20.         }
  21.         System.out.println(arr[n]);
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement