백준알고리즘 2839번 java

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner1 = new Scanner(System.in);
int three, five;
int num = scanner1.nextInt();
five = num / 5;
three = num % 5 / 3;
if (num == (five * 5) + (three * 3))
System.out.println(five + three);
else {
while (num != (five * 5) + (three * 3)) {
five--;
int temp = num;
temp -= (five * 5);
if (five > 0)
three = temp / 3;
else
three = temp / 3;
}
if((five<0) || (three <0))
System.out.println("-1");
else
System.out.println(three+five);
}
}
}


'SW > 백준알고리즘' 카테고리의 다른 글

백준알고리즘 10430번 java  (0) 2017.09.14
백준알고리즘 2558번 java  (0) 2017.09.14
백준알고리즘 2741번 java  (0) 2017.09.14
백준알고리즘 2472번 java  (0) 2017.09.14
백준알고리즘 2439번 java  (0) 2017.09.14