#include <stdio.h>
int main() {
// n은 설탕 갯수, total은 봉지의 최소 수 라서 최댓값으로 초기화함
int n,total=5000;
//최소 봉지수가 존재하는지 하나라도 존재하면 출력이니까 0으로 함
int is=0;
scanf("%d",&n);
//브루트 포스
for(int i=0; 3*i<=n; i++) {
for (int j=0; 3*i + 5*j<=n; j++) {
//n이랑 같고 i+j이 total(최솟값)보다 작으면 대입
//최소봉지수 있으면 1
if(n==3*i + 5*j && total > i+j) {
total=i+j;
is=1;
}
}
}
if(is) printf("%d",total);
else printf("-1");
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: