백준 2839 c++
#include <iostream>
using namespace std;
int input(int lower, int upper);
int count_bag(int n);
int main(void)
{
int N;
N = input(3, 5000);
cout << count_bag(N) << endl;
return 0;
}
int input(int lower, int upper)
{
int A;
while (1)
{
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
int count_bag(int n)
{
int i, j;
int bag_3 = n / 3, bag_5 = n / 5;
int count = bag_3 + bag_5;
for (i = 0; i <= bag_3; i++)
{
for (j = 0; j <= bag_5; j++)
{
if (i * 3 + j * 5 == n)
{
if (i + j < count)
{
count = i + j;
}
else
{
;
}
}
else
{
;
}
}
}
if(count != bag_3 + bag_5 || n == 3)
{
;
}
else
{
count = -1;
}
return count;
}